0

I am working on newsletter subscription bug. In this case the subscription status is always becoming not subscribed even when the customer chooses subscription. There are two cases.

Bug-1: When a customer creates account and opts or don't opt for subscription, his/her status is coming not subscribed.

Bug-2: There is edit option for subscription but that is also not working, customers are not able to change subscription status. If they are old customers and their status is subscribed, it remains subscribed - even when they edit to unsubscribe.

What I dug is that Magento provides module for newsletter subscription, and data for subscription goes into the table newsletter_subscriber.For first scenario nothing is going into this table for newly created accounts. For second case after editing subscription status ManageController/saveAction of newsletter module is called which calls setIsSubscribed() function on Mage::getModel('customer/session') object.

But there is no definition of setIsSubscribed() function. That means magic function is called. I am trying to solve these bugs. So I gave definition of setIsSubscription() into local/namespace/customer/model/customer and was able to solve bug number 2. But for bug-1 please someone give some suggestions and also please suggest if I did right thing for bug-2.

Thanks for your valuable time.

1 Answer 1

1

Newsletter subscription is done via events inside the module Mage_Newsletter. These events can be found by looking into the file resources/magento/src/store/app/code/core/Mage/Newsletter/etc/config.xml.

The main things to look for are the events customer_save_after and customer_delete_after.

customer_save_after

This will call Mage_Newsletter_Model_Observer::subscribeCustomer. Here the customer object is taken from the event and passed to Mage::getModel('newsletter/subscriber')->subscribeCustomer($customer);.

Now this function will check a few things against the customer object but in the end should update the newsletter status for the given customer.

customer_delete_after

This will call Mage_Newsletter_Model_Observer::customerDeleted. Here the subscriber object will be loaded by email address and then deleted.

$subscriber = Mage::getModel('newsletter/subscriber')
    ->loadByEmail($observer->getEvent()->getCustomer()->getEmail());
if($subscriber->getId()) {
    $subscriber->delete();
}

My guess is that either these events have been turned off for your system or they are not getting the right information because of a local or template change. You best bet for debugging would be to enable xdebug and set through these events to see what and why things are not working.

1
  • Thank you David thats all I needed, Mage::getModel('newsletter/subscriber')->subscribeCustomer($customer); is commented in Mage_Newsletter_Model_Observer::subscribeCustomer and thats why nothing is going into newsletter_subscriber table, thank you so much :)
    – seef07
    Oct 28, 2015 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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