0

I would like to have a timestamp stored for when a person subscribes or unsubscribes.

Looking at the database: specifically the table newsletter_subscription I see the field changed_status_at. However, this does not get populated, it is left null.

Evaluating the file /app/code/core/Mage/Subscriber.php I cannot see any reference to this field either.

Doing some research I found this link. However, after placing the suggested solution on the line(s) 350 and 376 of Subscriber.php it makes no difference and was still unchanged. Thus, is this a bug in magento and if so how would I correct this?

Update

After playing around with this, I placed ->setChangeStatusAt(Mage::getModel('core/date')->gmtDate('Y-m-d H:i:s')) before every save call in the file. For example,

$this->setSubscriberStatus(self::STATUS_UNSUBSCRIBED)
            ->setChangeStatusAt(Mage::getModel('core/date')->gmtDate('Y-m-d H:i:s'))
            ->save(); 

This looks to be setting the changed status date now. But, I can only see it if I go to manage customers. Thus, how could I:

A) do this without editing core files?

B) show this date in Newsletter => Newsletter Subscriptions

2

I assume that you have altered the newsletter_subscriber table and added the field to store the timestamp.

Answer for part A: By adding an observer to the event newsletter_subscriber_save_before in your config.xml:

<global>
    ....
    <events>
        ....
        <newsletter_subscriber_save_before>
            <observers>
                <your_unique_event_name>
                    <class>yourgroupname/observer</class>
                    <method>newsletterSubscriberChange</method>
                </your_unique_event_name>
            </observers>
        </newsletter_subscriber_save_before>
    </events>
</global>

You can then call getSubscriber() (see next code block) in your observer to get the Mage_Newsletter_Model_Subscriber model that allows you get data about the subscriber. This works for occurrences of subscription and unsubscriptions.

public function newsletterSubscriberChange(Varien_Event_Observer $observer) {
    $subscriber = $observer->getEvent()->getSubscriber();
    //now do whatever you want to do with the $subscriber

    //for example
    if($subscriber->isSubscribed()) {
        //...
    }

    // Your code to set timestamp

}

Answer of part B: You can extend the newsletter subscriber grid using your custom module and add the new column to show the new field.

You may need to use join in the _prepareCollection() function if you have created a custom table instead of adding the column to the newsletter_subscriber table.

Update: To know more about extending Newsletter Subscribers Grid, please check the following link:

Rewrite Admin Newsletter Grid

| improve this answer | |
  • Nope mate the change_status_at is a default field magento just doesn't seem to be using. Would you have a god tutorial for how to extend the newsletter subscriber grid? – Vaishal Patel May 29 '18 at 13:27
  • @VaishalPatel, please check my update in my answer. – Mohit Kumar Arora May 29 '18 at 13:45
  • I will do, shall test and accept accordingly if all works well. – Vaishal Patel May 29 '18 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.