- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2022
05:12 AM
12-05-2022
05:12 AM
Magento validating cart price rules always returning true for all the products
I have created a cart price rule for a configurable product. The rule condition has the SKU of the parent product. The functionality is working correctly. Now I want to show the description of the rule on the product page. The issue is that the description is showing for all the products whereas it should show only for this particular product.
$objrules = $objectManager->create('Magento\SalesRule\Model\RuleFactory')->create(); $rules = $objrules->getCollection(); foreach ($rules as $tmprule) { $rule = $objectManager->create('Magento\SalesRule\Model\Rule')->load($tmprule->getId()); $product = $objectManager->get('Magento\Catalog\Model\Product')->load($currentProduct->getId()); $item = $objectManager->create('Magento\Catalog\Model\Product'); $item->setProduct($product); if ($rule->getActions()->validate($item) && $rule->getIsActive()) { $product_disctxt=$rule->getDescription(); } } }
The rule validation code
$rule->getActions()->validate($item)
is always returning true for all the products.