Created
June 30, 2016 15:13
-
-
Save mwin007/35054cebe0fd75e684b884b300633081 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Belvg_SmartyApplyCatalogRule_Model_Rule extends Mage_CatalogRule_Model_Rule { | |
public function applyRule($rule_id) | |
{ | |
$rule = Mage::getModel('catalogrule/rule')->load($rule_id); | |
$this->_getResource()->updateRuleProductData($rule); //solution of the problem | |
$this->_getResource()->applyAllRulesForDateRange(); | |
$this->_invalidateCache(); | |
$indexProcess = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_price'); | |
if ($indexProcess) { | |
$indexProcess->reindexAll(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Apply all active catalog price rules | |
*/ | |
public function applyRulesAction() | |
{ | |
$errorMessage = Mage::helper('catalogrule')->__('Unable to apply rules.'); | |
try { | |
Mage::getModel('catalogrule/rule')->applyAll(); //the major culprit | |
Mage::getModel('catalogrule/flag')->loadSelf() | |
->setState(0) | |
->save(); | |
$this->_getSession()->addSuccess(Mage::helper('catalogrule')->__('The rules have been applied.')); | |
} catch (Mage_Core_Exception $e) { | |
$this->_getSession()->addError($errorMessage . ' ' . $e->getMessage()); | |
} catch (Exception $e) { | |
$this->_getSession()->addError($errorMessage); | |
} | |
$this->_redirect('*/*'); | |
} | |
/** | |
* Apply all price rules, invalidate related cache and refresh price index | |
* | |
* @return Mage_CatalogRule_Model_Rule | |
*/ | |
public function applyAll() | |
{ | |
$this->getResourceCollection()->walk(array($this->_getResource(), 'updateRuleProductData')); //the function 'updateRuleProductData' is applied by turn to each rule | |
$this->_getResource()->applyAllRulesForDateRange(); | |
$this->_invalidateCache(); | |
$indexProcess = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_price'); | |
if ($indexProcess) { | |
$indexProcess->reindexAll(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment