Catalog Price Rules “Apply Rules” programmatically

2019-07-17 04:30发布

问题:

I have created one Catalog Price Rule Programmatically it works fine.

so my issue is, I need to do login with admin and need click button of "Apply Rules" other wise discount is not apply in magento store, so i need "Apply Rules" programmatically and i have no idea about it how to do.

Any help or suggestion will be appreciated.

回答1:

You can Apply Rules using the below code with Newly created Catalogrule ID

$rule = Mage::getModel('catalogrule/rule')->load($ruleId);
Mage::getResourceModel('catalogrule/rule')->updateRuleProductData($rule);
Mage::getResourceModel('catalogrule/rule')->applyAllRulesForDateRange();
Mage::getModel('catalogrule/rule')->_invalidateCache();
$indexProcess = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_price');
if ($indexProcess) {
    $indexProcess->reindexAll();
}