Frage

How can we can place an if condition on proudct attibutes in a frontend .phtml file

enter image description here

In front end .phtml which is associated with our handle in custom module layout catalog_product_view , we get serialized_condition as

{"type":"Vendor\Module\Model\Rule\Condition\Combine","attribute":null,"operator":null,"value":"1","is_value_processed":null,"aggregator":"all","conditions":[{"type":"Vendor\Module\Model\Rule\Condition\Product","attribute":"category_ids","operator":"==","value":"2","is_value_processed":false}]}

How to get all attibutes and place an if condition on the attributes which matches our values in db table column name serialized_conditions like , if either the Sku ,climate,collar etc matches with the current product- do certain operation? Even if someone can provide directions about how it is done in the core files would be appreciated.

War es hilfreich?

Lösung

You can use magento2 core condition validate function , try the below code in your block or wherever you need it.

$id = 10;
$rule = $this->rule->create()->load($id);
        if ($rule->getConditions()->validate($this->getCurrentProduct())) {
                    return true;
        }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top