I'm trying to show the price rules in the product view, but I can not find a way to validate if a product meets the rule...

At the moment I just get all the rules.


class RuleDescription extends \Magento\Framework\View\Element\Template

    protected $_registry;
    protected $_collection;
    protected $_rule;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\SalesRule\Model\ResourceModel\Rule\CollectionFactory $collection,
        \Magento\SalesRule\Model\Rule $rule
        $this->_registry = $registry;
        $this->_collection = $collection;
        $this->_rule = $rule;

    public function getCurrentProduct()
        return $this->_registry->registry('current_product');

    private function getAllCartRules()
        return $this->_collection->create();

    public function getActiveCartRules()
        $product = $this->getCurrentProduct();

         * get cart price rule

        $rules = $this->getAllCartRules()->toArray();

I know it's not easy because of the amount of conditions, but is there any way?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.