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


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.

1 Answer 1


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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.