Skip to main content

Magento - Apply only one Catalog Price Rule


In default magento, on click of "Apply rules" in catalog price rules (Promotions > Catalog Price Rules), it get the products for all the active rules and add the data in a separate table. If there are more than five active rules, then lots of data have to be created and the process takes a lot of time. If we have to create a new rule, the save and apply will re-calculate for all the active rules.

The below code is to apply the rule only for the given rule id.

$rule = Mage::getModel('catalogrule/rule')->load($rule_id);
$rule->getResource()->updateRuleProductData($rule);
$rule->getResource()->applyAllRules();
$indexProcess = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_price');
if ($indexProcess) {
    $indexProcess->reindexAll();
}



Comments

Popular posts from this blog

Magento 2 - Create Attributes in Setup

Sometimes in our module we require to create product or category attributes automatically on module install. Also, we might require to add extra fields to quote, sales order, invoice, creditmemo tables. We will go through how to do that in magento 2. You can find the sample code in the git repo .