3

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.

0

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.

  • $item->getAppliedRuleIds(); Will it show the catalog rule name? – jack Apr 2 '18 at 13:18
  • It just returns the rule ids, we can loop this array to find the rule entity. – Khoa TruongDinh Apr 2 '18 at 14:06
  • Thanksf or your help! Just tried this method it's returning shopping cart rules but not Catalog Price rule. How can i load applied catalog price rule? Product of shoes cateogry have 5% discount based on catalog rule i want to display that on cart page. Above code is displaying cart rule. Any other way to detect catalog price rule? – jack Apr 3 '18 at 4:47
  • See more here: vendor/magento/module-sales-rule/Observer/SalesOrderAfterPlaceObserver.php. I updated my answer. – Khoa TruongDinh Apr 4 '18 at 3:34
  • For Catalog Price rule, it need to check. – Khoa TruongDinh Apr 4 '18 at 3:35

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.