I have been working for 2 days for applying multiple coupon on cart
I know there are modules which are available for that. But i don't want to use it. I want some custom code so that i can apply more than 1 coupon code in the single order.
Please help. i am very tired after working on the same stuff.
Best Answer
In your custom module, add the following to
config.xml
:The first is a rewrite of
Mage_SalesRule_Model_Quote_Discount
toNamespace_Module_Rewrite_SalesRule_Model_Quote_Discount
The second is the overloaded controller
Mage_Checkout_CartController
Next add the following file
app/code/community/Namespace/Module/controllers/Checkout/CartController.php
and insert the following code:You will notice i added a section to combine coupon codes delimited by ",". This can obviously be more refined and you may want to add additional checking etc, but this code should work straight off the bat.
And finally we need to add the piece that does all the magic. Add the file
app/code/community/Namespace/Module/Rewrite/SalesRule/Model/Quote/Discount.php
and add the content:
Basically, what this does is breaks the coupon sting up, loops through each coupon code, calculates and updates the quote totals.
To test, i have setup 2 shopping cart rules:
No coupon:
Added coupon test 1:
Added coupon test 2
I have tested with fixed amount discount and this works as expected as well.
And like i said, you may need to add additional checking, possibly for duplicates, but this is where you would start. For the frontend, you could add some logic split the codes however you prefer or leave as is.