0

I have created a newsletter template for giving 20% discount to customers by a dynamic coupon code. I created a shopping cart price rule with dynamic coupon code but I am unable to fetch that coupon code in Newsletter template.

How to get dynamic coupon code in newsletter email ?

1

The best way to do this I think is to create a system configuration to contain the discount code value and then reference the value in the email template.

  1. Create system config for the coupon you will be showing (select type) - You should create a module, I won't go into the details as you can easily find this elsewhere
  2. Create the source model for populating the select(ideally active coupons) - something like this

`class Phil_TransactionalEmails_Model_System_Config_Source_Couponcodes {

protected $_options;
public function toOptionArray(){
    $rulesCollection = Mage::getResourceModel('salesrule/rule_collection')->load();

    if (!$this->_options) {
        $this->_options = array();
        foreach ($rulesCollection as $item) {

            if ($item->getIsActive() == 1 && $item->getData('code') != null) {
                $_couponCode = Mage::helper('core')->escapeHtml($item->getData('code'));
                $_couponCodeName = Mage::helper('core')->escapeHtml($item->getData('name'));

                $this->_options[] = array(
                    'value' => $_couponCode,
                    'label' => $_couponCode . ' - ' . $_couponCodeName
                );
            }

        }
    }
    // Sort alphabetical
    usort($this->_options, function ($a, $b) {
        return strcmp($a['value'], $b['value']);
    });

    return $this->_options;

}

} `

Apologies for the formatting, cant seem to get it to work properly.

  1. Set up the permissions to allow the system config to be used in emails System > Permissions > Variables
  2. Reference the code in email template

{{config path='yourconfigpath'}}

If you don't care about it being manageable you can probably just create a variable directive and query the coupon by id for your specific coupon value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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