Mage Check Facebook iconFacebook MAGE CHECK Mage Check Linkedin iconLinkedin MAGE CHECK Mage Check Skype iconSkype MAGE CHECK

Magento how to Programmatically Subscribe

Step 1: Define Function

Magento 1

<?php class MageCheck_Tutorial_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction() { $this-> createSubscribe(); } public function createSubscribe() { // ... } }

Magento 2

/** * @var \Magento\Newsletter\Model\Subscriber */ protected $_subscriber; public function __construct( \Magento\Newsletter\Model\Subscriber $subscriber ){ $this->_subscriber = $subscriber; } public function execute() { $this->creatingSubscribe(); } public function creatingSubscribe() { // ... }

Step 2: Create Function

Magento 1

public function createSubscribe() { $customer = Mage::getModel('customer/customer') ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail('example@magecheck.com'); $customer->setConfirmation(true); $customer->save(); }

Magento 2

public function creatingSubscribe() { $email = 'example@magecheck.com'; $subscriber = $this->_subscriber; $subscriber->subscribe($email); $subscriber->save(); }

This is the sample way to Programmatically Subscribe in Magento!

Contact us

Have you decided on an online Business Plan website?