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?

  • Why just not to disable the products with given criteria in the shopping cart rile? – Amasty Aug 18 '14 at 19:13

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.

| improve this answer | |

In your observer

public function myCouponObserver($event){
  //get quote
  $quote = $event->getQuote();

Get all item (parent)

$cartItems = $quote->getAllVisibleItems();

foreach ($cartItems as $item) {
    //check for sku
    if($item->getSku() == 'xyz'){


To get Coupon

$coupon_code = $quote->getCouponCode();

To remove coupon

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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