4

I've viewed some articles on creating shopping cart rules programmatically, but what I can't find is how to combine multiple actions into the one coupon code.

What I need to do is apply 15% discount to the cart AND add on a free item when a coupon is used. I've bought a plugin to allow me to add the free product, I just need to find a way to apply both actions to one coupon code.

Thanks in advance

3

Create 2 shopping cart rules with the same coupon code. That's it. Just remove the unique key index from the database and the rule model (you can create a new extension for this)

  • 1
    is there any negative effect from removing this unique key from the salesrule_coupon.code? Also, what needs to be modified in the rule model (Mage_SalesRule_Model_Rule?)? – musicliftsme Mar 23 '15 at 18:25
  • @Amasty, how to remove unique key index? – Baby in Magento Jun 5 '15 at 13:11
  • Use DROP INDEX index_name ON tbl_name – Amasty Jun 9 '15 at 11:24
  • ALTER TABLE salesrule_coupon DROP INDEX UNQ_SALESRULE_COUPON_CODE; – Ben Truby Sep 1 '15 at 14:07
2

For anybody who finds this question, the answer is on here: Using the same Coupon code for multiple Price Rules

It expands on the answer by @Amasty (deleting the unique code index from the database) but crucially it reveals the changes you need to make to Mage_SalesRule_Model_Resource_Coupon

To get it working I copied:

Mage/SalesRule/Model/Resource/Coupon.php

to

local/Mage/SalesRule/Model/Resource/Coupon.php

and commented out this statement:

$this->addUniqueField(array(
            'field' => 'code',
            'title' => Mage::helper('salesrule')->__('Coupon with the same code')
        ));

I also found it helped to ensure the two coupons had different labels - but I have a feeling that was an extension complaining rather than Magento core.

1
Condition = What are the condition to enable the rules

and

Action = On which product do you apply the rules.

Example if you're rules is productA get 10% discount

Condition = no condition, this rule always apply

Action = 10% if SKU is productA

Example 2 if you're rule is productA get 10% only if you have at least 3 productB in your cart

Condition = quantity in the cart of productB is greater than 2

Action = 10% is SKU is productA

Discount will only get applied on productA, but there is a condition to have this discount applied (have 3 productB or more in your cart).

1

After deleting the index in salesrule_coupon table (in my case the table had a prefix xxx_ so the index had a similar name) I was receiving the same error from my admin. What I did was to create a new rule with a different coupon name, set all the conditions ets, and then go back to the database and edit the row to rename the coupon name. So now I have two rule with the same coupon name (tested and works fine in cart).

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