Monday, July 3, 2017

Magento 1.9 Newsletter Unsubscribe Link Not Working

Yes.... still we are working on Magento 1.9 as Magento 2.0 is bit difficult to work with and there were some bugs in it. So recently we created magento store with Magento 1.9 where we faced an issue of adding unsubscribe link in subscription success email and other newsletter.

Subscriber object is shared with all the newsletter email templates. So to add unsubscribe link you just have to add following code.

<a href="{{var subscriber.getUnsubscriptionLink() }}"> Unsubscribe </a>

 But somehow this was not working. So after checking system log we found following error.

getUnsubscribeUrl function not found for Mage_Newsletter_Helper_Data class.

Now this was a strange issue as this is the basic functionality of Magento 1.9 and it is not working. So I checked the Mage_Newsletter_Helper_Data class in app/code/core/Mage/Newsletter/Helper folder and there was no such function but the function name was different.

Following is the function found in data.php

public function getUnsubscribeLink($subscriber)
    {
        return Mage::getModel('core/url')
            ->setStore($subscriber->getStoreId())
            ->getUrl('newsletter/subscriber/unsubscribe', array(
                'id'     => $subscriber->getId(),
                'code'   => $subscriber->getCode(),
                '_nosid' => true
            ));
    }

And in app/code/core/Mage/Newsletter/Model/Subscriber.php file following is the function.

public function getUnsubscriptionLink() {
        return Mage::helper('newsletter')->getUnsubscribeUrl($this);
    }

Which was used in template. So that was the issue. So to solve this issue replace above function with following function in app/code/core/Mage/Newsletter/Model/Subscriber.php file.

public function getUnsubscriptionLink() {
        return Mage::helper('newsletter')->getUnsubscribeLink($this);
    }

And now it should work. Hope this helps you.