I have the following block of code that gets all active catalog rules:
$catalog_rule_collection = $objectManager ->create('\Magento\CatalogRule\Model\RuleFactory') ->create() ->getCollection() ->addFieldToFilter('simple_action', 'by_percent') ->addIsActiveFilter(1);
->addFieldToFilter('simple_action', 'by_percent') filters results to catalog rules with a percentage discount.
->addIsActiveFilter(1) filters results to only activated catalog rules.
This simply retrieves table data from the
catalogrule table. The following SQL query would achieve the same result:
SELECT discount_amount FROM catalogrule WHERE simple_action = 'by_percent' AND is_active = 1
How do I filter results by store-ID-specific catalog rules? So if a catalog rule affects store 1 but not store 2, how can I express the following:
Consider that the
catalogrule table does not have a
store column, nor is the store ID specified in the
actions_serialized tables. Yet in Magento 2, catalog rules can be set uniquely by store.