Magento – Magento 2 check which catalog rule is applied to cart product

cartcatalog-price-rulesmagento2magento2.2programmatically

I have created 3 catalog rules for category.

  1. Shoes Category: 5% Off , Catalog Rule Name: Shoes Offer
  2. Toys Category: 10% Off, Catalog Rule Name: Toys Offer
  3. Fashion Accessories: 8% Off, Catalog Rule Name: Fashion Acc. Offer

So all the product of that categories are showing discounted price in category.
On cart page i want to show which catalog rule is applied to item.

Is there any way to check on cart item that which catalog rule is applied to it?

How can i check which catalog rule is applied to item and how much discount is applied?

Any help would be appreciated.

Best Answer

We can use \Magento\Quote\Model\Quote\Item $item to check the applied rules.

vendor/magento/module-sales-rule/Model/Quote/Discount.php

 $item->getAppliedRuleIds();
 $item->getDiscountAmount();

See a good example here: vendor/magento/module-sales-rule/Observer/SalesOrderAfterPlaceObserver.php

In database, we should take a look at quote_item table.

Related Topic