1

I want to add some custom condition based on cart item's custom option on coupon code.

For this I am using salesrule_validator_process event and also added code for cart item's custom option condition but how to remove coupon or not allow to apply when condition not matched?

Here is my code :

$quote = Mage::getSingleton('checkout/session')->getQuote();
$cartItems = $quote->getAllVisibleItems();
foreach ($cartItems as $item) 
{
    $info_buyRequest = $item->getOptionByCode('info_buyRequest');
    $buyRequest = unserialize($info_buyRequest->getValue());
    if($custom_condition)
    {
        return true;
    }
    else
    {
        return false;       // here I want to remove coupon or not allow to apply
    }
}

How to do that?

1 Answer 1

6

Replace below code and check :

$quote = Mage::getSingleton('checkout/session')->getQuote();
$cartItems = $quote->getAllVisibleItems();
foreach ($cartItems as $item) 
{
    $info_buyRequest = $item->getOptionByCode('info_buyRequest');
    $buyRequest = unserialize($info_buyRequest->getValue());
    if($custom_condition)
    {
        return true;
    }
    else
    {
       //To remove coupon

       $quote->setCouponCode('');
       $quote->collectTotals()->save();

    }
}

Let me know if not work.

1
  • my quote has discount because it is category wise not coupon code needed,how can i do thsat? Commented Dec 8, 2018 at 5:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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