I have a shopping cart rule setup which applies a discount if the product has a specific attribute - there's no coupon code involved.

Throughout the site I just need to check whether or not that shopping cart rule has been applied to the quote.

I've tried this:

$coupon_code = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();

But that doesn't work; it only works with coupon codes input by the user.

How would I check if such a shopping cart rule has been applied?

$appliedRuleIds = Mage::getSingleton('checkout/session')->getQuote()->getAppliedRuleIds();

This will give you the ids of the rules applied to the quote separated by comma.
you can turn them into an array like this:

$appliedRuleIds = explode(',', $appliedRuleIds);

if you want to get the rules applied as objects you can do this:

//$rules = Mage::getModel('salesrule/rule')->getCollection()->addFieldToFilter('rule_id' => array('in' => $appliedRuleIds));
$rules =  Mage::getModel('salesrule/rule')->getCollection()->addFieldToFilter('rule_id' , array('in' => $appliedRuleIds));

foreach ($rules as $rule) {
    //do something with $rule
  • hi marius, i have to apply similar solution. but getAppliedRuleIds stores both catalog price rule and shopping cart price rule. Now if the field value is only 6 (which is catalog price rule) and a shopping cart price rule too exists in store with id 6. in this case, with your solution, how can we define which one was applied ? shopping cart price rule or catalog price rule ? any help is appreciated. Jun 26 '15 at 14:24
  • @ReenaParekh. I'm almost certain the getAppliedRuleIds does not return the catalog price rules applied to the quote/order. Only shopping cart price rules that are applied.
    – Marius
    Jun 26 '15 at 14:27
  • Hi @Marius , I too need to get the same thing what you have mentioned in above code in magento2.2.2. So Please tell me how do I solve the same issue in magento 2
    – Jaisa
    Feb 28 '18 at 7:28
  • Hi @Marius How can we get discount amount from quote based on rule id? Mar 2 '19 at 6:41

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.