Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I encountered a situation where I needed to listen for subscription/unsubscription events. I encountered this question and thought I would leave this solution here for anyone that may need it:</p> <p>By adding an observer to the event <code>newsletter_subscriber_save_before</code> in your config.xml:</p> <pre><code>&lt;global&gt; .... &lt;events&gt; .... &lt;newsletter_subscriber_save_before&gt; &lt;observers&gt; &lt;your_unique_event_name&gt; &lt;class&gt;yourgroupname/observer&lt;/class&gt; &lt;method&gt;newsletterSubscriberChange&lt;/method&gt; &lt;/your_unique_event_name&gt; &lt;/observers&gt; &lt;/newsletter_subscriber_save_before&gt; &lt;/events&gt; &lt;/global&gt; </code></pre> <p>You can then call <code>getSubscriber()</code> (in the context of <code>$observer-&gt;getEvent()</code>, see next code block) in your observer to get the <code>Mage_Newsletter_Model_Subscriber</code> model that allows you get data about the subscriber. This works for occurrences of subscription and unsubscriptions.</p> <pre><code>public function newsletterSubscriberChange(Varien_Event_Observer $observer) { $subscriber = $observer-&gt;getEvent()-&gt;getSubscriber(); //now do whatever you want to do with the $subscriber //for example if($subscriber-&gt;isSubscribed()) { //... } //or if($subscriber-&gt;getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) { //... } elseif($subscriber-&gt;getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED) { //.. } } </code></pre> <p>So it turns out this is really easy. These model events are super powerful and let you do things like this super easily. Can't turn down free functionality!</p> <p>For quick reference, here is <a href="http://php.r3dcode.com/files/Magento/1.7/0.2/app/code/core/Mage/Newsletter/Model/Subscriber.php#n28">what data the <code>Mage_Newsletter_Model_Subscriber</code> model provides</a> (1.7)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload