Aug 21, 2014
kalpesh

Magento event to check if customer have subscribed to newsletter

Check if the customer has subscribed to the newsletter from registration page or checkout page by using event observer. You may need to take some action programatically if customer subscribes to newsletter, below code will help you exactly in that.

Code to put in your config.xml

1
2
3
4
5
6
7
8
<newsletter_subscriber_save_after>
  <observers>
    <namespace_module_model_observer>
      <class>Namespace_Module_Model_Observer</class>
      <method>subscribedToNewsletter</method>
    </namespace_module_model_observer>
  </observers>
</newsletter_subscriber_save_after>

Code to put in your Observer.php file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Namespace_Module_Model_Observer {
        public function subscribedToNewsletter(Varien_Event_Observer $observer)
    {
        $event = $observer->getEvent();
        $subscriber = $event->getDataObject();
        $data = $subscriber->getData();
        $email = $data['subscriber_email'];
        
        
        $statusChange = $subscriber->getIsStatusChanged();
        if ($data['subscriber_status'] == "1" && $statusChange == true) {
                        //code to handle if customer is just subscribed...
                }
        }
}

1 Comment

Leave a comment

 

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications