Monday , December 11 2017
Home >> All tutorial >> How to disable Magento default newsletter transactional emails

How to disable Magento default newsletter transactional emails

Not everyone is satisfied with Magento’s options regarding newsletters so they choose to use some 3rd party service (like MailChimp). In that case it might be a good idea to disable Magento’s default newsletter transactional emails and let that other 3rd party service take care of emails.

In this tutorial I’ll demonstrate how to disable those default Magento’s newsletter transactional emails.

For start we’ll rewrite core model in our config.xml

  1. <newsletter>
  2.     <rewrite>
  3.         <subscriber>Inchoo_Newsletter_Model_Newsletter_Subscriber</subscriber>
  4.     </rewrite>
  5. </newsletter>

It might be a good idea to put config option so store owner can turn on / off default emails anytime he wants to.

We’ll start that by creating system.xml and putting this block of code in it:

  1. <?xml version=“1.0”?>
  2. <config>
  3.     <tabs>
  4.         <inchoo_tab translate=“label”>
  5.             <label>Inchoo</label>
  6.             <sort_order>200</sort_order>
  7.         </inchoo_tab>
  8.     </tabs>
  9.     <sections>
  10.         <inchoo_newsletter translate=“label”>
  11.             <label>Newsletter Configuration</label>
  12.             <tab>inchoo_test_tab</tab>
  13.             <frontend_type>text</frontend_type>
  14.             <sort_order>1</sort_order>
  15.             <show_in_default>1</show_in_default>
  16.             <show_in_website>1</show_in_website>
  17.             <show_in_store>1</show_in_store>
  18.             <groups>
  19.                 <newsletter_subscription_transactional_mails>
  20.                     <label>Newsletter Subscription Transactional Mails</label>
  21.                     <frontend_type>text</frontend_type>
  22.                     <show_in_default>1</show_in_default>
  23.                     <show_in_website>1</show_in_website>
  24.                     <show_in_store>1</show_in_store>
  25.                     <sort_order>120</sort_order>
  26.                     <fields>
  27.                         <enabled translate=“label”>
  28.                             <label>Enable</label>
  29.                             <frontend_type>select</frontend_type>
  30.                             <source_model>adminhtml/system_config_source_yesno</source_model>
  31.                             <sort_order>40</sort_order>
  32.                             <show_in_default>1</show_in_default>
  33.                             <show_in_website>1</show_in_website>
  34.                             <show_in_store>1</show_in_store>
  35.                         </enabled>
  36.                     </fields>
  37.                 </newsletter_subscription_transactional_mails>
  38.             </groups>
  39.         </inchoo_newsletter>
  40.     </sections>
  41. </config>

Next we’ll add path to our config option inside Helper class and a method to retrieve its value:

  1. class Inchoo_Newsletter_Helper_Data extends Mage_Core_Helper_Abstract
  2. {
  3.     const XML_PATH_NEWSLETTER_MAILS  = ‘inchoo_newsletter/newsletter_subscription_transactional_mails/enabled’;
  4.     public function getNewsletterSubscriptionMailEnabled()
  5.     {
  6.         return Mage::getStoreConfig(self::XML_PATH_NEWSLETTER_MAILS);
  7.     }
  8. }

Final step is editing few core methods from the class which we previously rewrote.
Our new model class is Inchoo_Newsletter_Model_Newsletter_Subscriber and it must extend core class Mage_Newsletter_Model_Subscriber. Name of the class depends on your module, however, we always need to extend core class, otherwise it will not work.

You’ll need to copy 3 methods from the core class into our new class and make small adjustments to them.

  • public function subscribe($email)
  • public function subscribeCustomer($customer)
  • public function unsubscribe()

Inside subscribe method find following

  1. if ($isConfirmNeed === true
  2.     >> $isOwnSubscribes === false
  3. ) {
  4.     $this->sendConfirmationRequestEmail();
  5. } else {
  6.     $this->sendConfirmationSuccessEmail();
  7. }

And replace it with our

  1. if ((bool) Mage::helper(‘inchoo_newsletter’)->getNewsletterSubscriptionMailEnabled()) {
  2.     if ($isConfirmNeed === true >> $isOwnSubscribes === false) {
  3.         $this->sendConfirmationRequestEmail();
  4.     } else {
  5.         $this->sendConfirmationSuccessEmail();
  6.     }
  7. }
 For subscribeCustomer method find:

  1. if ($this->getIsStatusChanged() >> $status == self::STATUS_UNSUBSCRIBED) {
  2.     $this->sendUnsubscriptionEmail();
  3. } elseif ($this->getIsStatusChanged() >> $status == self::STATUS_SUBSCRIBED) {
  4.     $this->sendConfirmationSuccessEmail();
  5. }

And replace it with:

  1. if ((bool) Mage::helper(‘inchoo_newsletter’)->getNewsletterSubscriptionMailEnabled()) {
  2.     if ($this->getIsStatusChanged() >> $status == self::STATUS_UNSUBSCRIBED) {
  3.         $this->sendUnsubscriptionEmail();
  4.     } elseif ($this->getIsStatusChanged() >> $status == self::STATUS_SUBSCRIBED) {
  5.         $this->sendConfirmationSuccessEmail();
  6.     }
  7. }

In the last method unsubscribe find:

  1. $this->sendUnsubscriptionEmail();

And replace it with:

  1. if ((bool) Mage::helper(‘inchoo_newsletter’)->getNewsletterSubscriptionMailEnabled()) {
  2.     $this->sendUnsubscriptionEmail();
  3. }

What this means is that we’re first checking whether or not our config option is set to enabled or disabled. If it’s set to disabled then do not execute the code inside if statement which is charge of sending those transactional emails.

 Magento Tutorial By Inchoo.net

We also contribute great content of Magento Download for FREE (all versions)

DON'T MISS THE CHANCE!

magento download

About Champ

Leave a Reply

Your email address will not be published. Required fields are marked *

Heap | Mobile and Web Analytics