1

I have created an admin form which contains name and catalog price rule conditions. I have saved these values in a custom table. The conditions are saved as serialized. Now I want to check these conditions against each product in catalog product list page, product page, widgets etc. If the condition satisfied then need to display the name in each product.

How can I do this. Please help me.

  • Did you get any solution for this – divya sekar Nov 22 '19 at 7:56
  • Did you get any solution for this, please share – Purushotam Sharma Dec 24 '19 at 14:08
0

You can use as example the standard Magento class Magento\Rule\Model\AbstractModel or just extend it in your custom class. The algorithm is pretty simple:

1) Load conditions data ($conditionsSerialized = $this->getConditionsSerialized())) and unserialize it ($conditions = $this->serializer->unserialize($conditionsSerialized);)

2) Get the conditions object (instance of \Magento\Rule\Model\Condition\Combine or what ever you use) and load it using recently loaded data as array ($this->_conditions->loadArray($conditions);)

3) Validate your object using this condition ($this->_conditions->validate($object);)

|improve this answer|||||
  • This validate only the customer group, dates and website Ids. I want to validate against the product too. ie, in product view I want to check the rule is applicable for this product or not – Jancy Abraham May 20 '19 at 3:18
  • @JancyAbraham The conditions class is responsible for the product validation, so you should update it if you wish to add custom validation. – Siarhey Uchukhlebau May 20 '19 at 7:35
  • Can you please explain it briefly. – Jancy Abraham May 20 '19 at 7:40
  • @JancyAbraham I'll try to create a simple example for you with all classes – Siarhey Uchukhlebau May 20 '19 at 7:51
  • Can I get the example please. – Jancy Abraham May 23 '19 at 5:33

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.