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:
->addStoreFilter(1) //pseudocode
Consider that the catalogrule
table does not have a store
column, nor is the store ID specified in the conditions_serialized
or actions_serialized
tables. Yet in Magento 2, catalog rules can be set uniquely by store.
website_ids
attributecatalogrule
table's first column isrule_id
which joins with thecatalogrule_website
table. That table has the column forwebsite_id
. So you're very close to answering my question. Now for example;\Magento\CatalogRule\Model\RuleFactory
gets thecatalogrule
table. All I need to know now is the namespace which references thecatalogrule_website
table.