MyPage is a personalized page based on your interests.The page is customized to help you to find content that matters you the most.


I'm not curious

How to Disable Default Newsletters on Magento?

Published on 19 May 15
0
3
How to Disable Default Newsletters on Magento? - Image 1
Many of you are not really happy with the default newsletter available with Magento. You tend to use third party mail services to accomplish the email newsletter related tasks. Since, you are using the third party service; you should ideally disable the default newsletter that comes with Magento. Let’s see how to disable default newsletters on Magento.

Rewrite Core Magento Model

Go to config.xml and begin with rewriting the core model
<newsletter>
<rewrite>
<subscriber>Example_Newsletter_Model_Newsletter_Subscriber</subscriber>
</rewrite>
</newsletter>
When you put it within the config option, you are actually allowing the store owner to decide whether or not they want to keep the config option.

Create System.xml

Your next step is to create system.xml and paste the code given below to it


<?xml version="1.0"?>

<config>
<tabs>
<example_tab translate="label">
<label>Example</label>
<sort_order>200</sort_order>
</example_tab>
</tabs>

<sections>
<example_newsletter translate="label">
<label>Newsletter Configuration</label>
<tab>example_test_tab</tab>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<newsletter_subscription_transactional_mails>
<label>Newsletter Subscription Transactional Mails</label>
<frontend_type>text</frontend_type>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<sort_order>120</sort_order>
<fields>
<enabled translate="label">
<label>Enable</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>40</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</enabled>
</fields>
</newsletter_subscription_transactional_mails>
</groups>
</example_newsletter>
</sections>
</config>
Add a Path Within Helper Class

Using the code below, you can easily add a path to the helper class
class Example_Newsletter_Helper_Data extends Mage_Core_Helper_Abstract
{
const XML_PATH_NEWSLETTER_MAILS = 'example_newsletter/newsletter_subscription_transactional_mails/enabled';

public function getNewsletterSubscriptionMailEnabled()
{
return Mage::getStoreConfig(self::XML_PATH_NEWSLETTER_MAILS);
}
}
The new class created for this purpose is Example_Newsletter_Model_Newsletter_Subscriber . you need to extend this class to the core class Mage_Newsletter_Model_Subscriber

Now copy paste three methods from the core class to the new class and make small modifications accordingly

The three minor modifications include

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

Replace the code in subscribe method
if ($isConfirmNeed === true
&& $isOwnSubscribes === false
) {
$this->sendConfirmationRequestEmail();
} else {
$this->sendConfirmationSuccessEmail();
}
With
if ((bool) Mage::helper('example_newsletter')->getNewsletterSubscriptionMailEnabled()) {
if ($isConfirmNeed === true && $isOwnSubscribes === false) {
$this->sendConfirmationRequestEmail();
} else {
$this->sendConfirmationSuccessEmail();
}
}
Similarly, the following code in subscribecustomer method()
if ($this->getIsStatusChanged() && $status == self::STATUS_UNSUBSCRIBED) {
$this->sendUnsubscriptionEmail();
} elseif ($this->getIsStatusChanged() && $status == self::STATUS_SUBSCRIBED) {
$this->sendConfirmationSuccessEmail();
}
Should be replaced with
if ((bool) Mage::helper('example_newsletter')->getNewsletterSubscriptionMailEnabled()) {
if ($this->getIsStatusChanged() && $status == self::STATUS_UNSUBSCRIBED) {
$this->sendUnsubscriptionEmail();
} elseif ($this->getIsStatusChanged() && $status == self::STATUS_SUBSCRIBED) {
$this->sendConfirmationSuccessEmail();
}
}
Finally in the unsubscribe method the following code
$this->sendUnsubscriptionEmail();
Should be replaced with
if ((bool) Mage::helper('example_newsletter')->getNewsletterSubscriptionMailEnabled()) {
$this->sendUnsubscriptionEmail();
}
With this code, you check if the default mails are set to enable/disable mode, and accordingly decide whether to execute the code or not.

Conclusion

When you are already using a third party service for your newsletters, it makes sense to disable the default newsletter that comes with Magento. To disable, you can use the code given in this tutorial. This code checks whether the default newsletter has been enabled/disabled, and accordingly decides whether or not to execute the code.

Note: It is always a good idea to backup the default code before executing a new code.

Author Bio:

Deepa is a passionate blogger associated with Silver Touch Technologies., a leading Magento Development Company UK. If you are looking to hire Magento Developer UK then just get in touch with her.
This blog is listed under Development & Implementations and E-Commerce Community

Related Posts:
Post a Comment

Please notify me the replies via email.

Important:
  • We hope the conversations that take place on MyTechLogy.com will be constructive and thought-provoking.
  • To ensure the quality of the discussion, our moderators may review/edit the comments for clarity and relevance.
  • Comments that are promotional, mean-spirited, or off-topic may be deleted per the moderators' judgment.
You may also be interested in
 
Awards & Accolades for MyTechLogy
Winner of
REDHERRING
Top 100 Asia
Finalist at SiTF Awards 2014 under the category Best Social & Community Product
Finalist at HR Vendor of the Year 2015 Awards under the category Best Learning Management System
Finalist at HR Vendor of the Year 2015 Awards under the category Best Talent Management Software
Hidden Image Url

Back to Top