0

I have a catalog price rule whose one condition is short_description contains Discount word. For the rules having contains condition with flat catalog enabled system we need to disable flat catalog and apply the rule then again enable it.

I am doing it via below code, this is working in default magento but not working on my site. My site having approx 15000 products and enabled product flat catalog.

$rule = Mage::getModel('catalogrule/rule')->load(14);
$rule->setIsActive(0); //Set rule Inactive
$rule->save();
//Apply Rule
Mage::getResourceModel('catalogrule/rule')->updateRuleProductData($rule);
Mage::getResourceModel('catalogrule/rule')->applyAllRulesForDateRange();


//Flat Catalog Disable
Mage::getModel('core/config')->saveConfig('catalog/frontend/flat_catalog_product', '0', 'default', 0);


$rule1 = Mage::getModel('catalogrule/rule')->load(14);
$rule1->setIsActive(1); //Set rule active
$rule1->save();
//Apply Rule
Mage::getResourceModel('catalogrule/rule')->updateRuleProductData($rule1);
Mage::getResourceModel('catalogrule/rule')->applyAllRulesForDateRange();


//Flat Catalog Enable
Mage::getModel('core/config')->saveConfig('catalog/frontend/flat_catalog_product', '1', 'default', 0);

Mage::getModel('core/config')->cleanCache();

$process = Mage::getModel('index/process')->load(2); //Product Price index
$process->reindexAll();
$process1 = Mage::getModel('index/process')->load(4); //Product Flat Data index
$process1->reindexAll();

Mage::app()->cleanCache();

But when I check catalogrule_product table no entry for this rule and products. But when I apply these steps manually its working.

I have found below in system.log, As this work has been done on admin panel config. button click (ajax).

HEADERS ALREADY SENT: <pre>[0] /var/www/html/magento/app/code/core/Mage/Core/Controller/Response/Http.php:52
[1] /var/www/html/magento/lib/Zend/Controller/Response/Abstract.php:768
[2] /var/www/html/magento/app/code/core/Mage/Core/Controller/Response/Http.php:84
[3] /var/www/html/magento/app/code/core/Mage/Core/Controller/Varien/Front.php:184
[4] /var/www/html/magento/app/code/core/Mage/Core/Model/App.php:365
[5] /var/www/html/magento/app/Mage.php:719
[6] /var/www/html/magento/index.php:94

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.