I have a number of coupon codes which i want to apply to the cart programmatically.
I have done it like this:
foreach ($coupons as $coupon) //$coupons array of coupon codes
{
Mage::getSingleton('checkout/cart')
->getQuote()
->setCouponCode($coupon)
->collectTotals()
->save();
}
Now what happens is that if the first coupon is valid, it got applied, but after that
- if the second coupon is valid, it got replaced (first removed, second applied).
- if the second coupon is not valid it removes the discount applied by the first coupon too.
Now I need help to tackle the situation as how to be able to apply both coupon/rules/discounts if valid (if possible applying two coupon codes)? or not apply coupon code if not valid so that the coupon applied before doesn't got removed.