I want to remove the SalesRule from Quote if rule Coupon type is
Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON
I have this code:
$event = $observer->getEvent();
$quote = $event->getQuote();
$address = $quote->getShippingAddress();
$appliedRule = $event->getRule();
if (strlen($quote->getCouponCode()) > 0) {
$quote->setCouponCode('');
$quote->collectTotals()->save();
}
return $this;
which works fine if I want to remove the Coupon code which I set in the salesRule. But same rule does not work for Coupon type which I have mentioned above.
I have tried solutions like iterating through quote Items and setting the appliedRules to null and discount amount, value to zero but nothing worked. E.g.
$event = $observer->getEvent();
$quote = $event->getQuote();
$address = $quote->getShippingAddress();
$appliedRule = $event->getRule();
$giftcards = $quote->getGiftCards();
$giftCardsData = unserialize($giftcards);
if ($appliedRule->getCouponType() == Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON) {
foreach($quote->getAllVisibleItems() as $item) {
$item->setAppliedRuleIds('');
$item->setDiscountPercent(0);
$item->setDiscountAmount(0);
$item->setBaseDiscountAmount(0);
$item->save();
}
}
Or also tried setting AppliedRules to null in QUOTE and ADDRESS:
if ($appliedRule->getCouponType() == Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON) {
$address->setAppliedRuleIds('');
$quote->setAppliedRuleIds('');
}
But no success so far. I will be great full if someone can tell me how can I remove the SalesRule from the Quote.
By the way above code is running under
salesrule_validator_process
Event.