9

I need to get all discounted price from each cart rule which is applied on current quote. I am getting applied rule ids from $quote->getAppliedRuleIds() and I am getting total discounted amount but I am not sure how can I get discount price of each rule if multiple rules applied to quote.

For example, in quote 3 cart rules applied and each cart rule has different discount(10+20+30) at the code level I am getting total discount amount 60 which is correct but I need (10+20+30) as separate.

Is there any way to get this?

3 Answers 3

0

Try this,

Inject \Magento\Checkout\Model\Cart class

$items = $cart->getQuote()->getAllItems();

  foreach ($items as $item) {
    $discountAmt = $item->getDiscountAmount(); //$item(get all information)
  }

Thanks!

0

Please try this, loop through the quote visible items,
we will get the discount amount per item-wise.

$cartItems = $quote->getAllVisibleItems();
foreach ($cartItems as $item) {
$itemDiscountAmount = $item->getDiscountAmount();
}
0

Bro, try digging in this function

\Magento\SalesRule\Model\RulesApplier::eventFix

which fires 'salesrule_validator_process' event with discount data for each rule applied.
In your observer, you can put the breakdown in a registry then print them out in a checkout page LayoutProcessor block.

Cheers.

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.