Magento – Multiple Shopping Cart Price Rules using the same Coupon Code

This has just gone into production so I can’t 100% vouch for it, but it looks like you can remove the unique index on a coupon code in magento v1.6 (I think the new versions have improved functionality so a coupon can be used with multiple rules).

This means the same coupon code can have multiple rules (for example offering free post off any item purchased, as well as another benefit such as a discount if a certain item is in the basket).

The table in the mySQL database “salesrule_coupon” needs the index “UNQ_SALESRULE_COUPON_CODE” removed…

database_change

The file /app/code/core/Mage/SalesRule/Model/Resource/Coupon.php needs the function_construct() updated…

FROM:

protected function _construct()
    {
        $this->_init('salesrule/coupon', 'coupon_id');
        $this->addUniqueField(array(
            'field' => 'code',
            'title' => Mage::helper('salesRule')->__('Coupon with the same code')
        ));
    }

TO:

protected function _construct()
    {
        $this->_init('salesrule/coupon', 'coupon_id');
        #$this->addUniqueField(array(
        #    'field' => 'code',
        #    'title' => Mage::helper('salesRule')->__('Coupon with the same code')
        #));
    }

You can then create multiple rules, and specify the same coupon code.