Magento – Apply coupon observer to set message in cart view

cart-rulecouponevent-observer

I've created observer method for salesrule_validator_process event. How can I access coupon code and whole cart to check, if there are specific products in cart? If it found products with a specific criteria how to disable applying entered coupon?

Best Answer

The event salesrule_validator_process passes most of the objects that you are looking for.

Mage::dispatchEvent('salesrule_validator_process', array(
    'rule'    => $rule,
    'item'    => $item,
    'address' => $address,
    'quote'   => $quote,
    'qty'     => $qty,
    'result'  => $result,
));

Here you have the quote (which is the cart). In your method your can call $observer->getQuote().

You can then loop through the items attached to the quote and perform your checks.

Related Topic