1

Having multiple promotions (or discounts) applied for shopping carts, how to get such promotions so I can display them in view?

Update: I want to get each. NOT the total. This is so I can display the labels of each promotions/discounts for the cart. Such as:

Sub Total: 100.00
Discounts:
   First Purchase: -10 (10%),
   Employee Discount: 5 (5%)
Shipping Fee: 20.00
Grand Total: 105
2
  • do u want the total discount amount or the shopping cart rules applied ? Commented Jul 1, 2016 at 10:32
  • I want to get to shopping cart rules applied as list not the totals. Commented Jul 1, 2016 at 10:42

1 Answer 1

3
$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));

foreach ($rules as $rule) {
    //do something with $rule
}
3
  • Thanks, I'm now trying this out. I'll let you if this works. Commented Jul 1, 2016 at 10:54
  • This works. I'm getting the IDs of the applied rules. Now how do I get the name/label of the rule? Dumping the $rule returns too much data and causes the page to hang. Commented Jul 4, 2016 at 2:05
  • Got it! To get the rule label or name: $rule->name Commented Jul 4, 2016 at 2:18

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.