Created
September 16, 2013 22:31
-
-
Save IvanChepurnyi/6587481 to your computer and use it in GitHub Desktop.
Optimized catalog price rules
This file contains 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 | |
class EcomDev_Optimization_Model_Rule_Observer extends Mage_CatalogRule_Model_Observer | |
{ | |
protected $_preloadedPrices = array(); | |
public function beforeCollectTotals(Varien_Event_Observer $observer) | |
{ | |
$quote = $observer->getQuote(); | |
$date = Mage::app()->getLocale()->storeTimeStamp($quote->getStoreId()); | |
$websiteId = $quote->getStore()->getWebsiteId(); | |
$groupId = $quote->getCustomerGroupId(); | |
$productIds = array(); | |
foreach ($quote->getAllItems() as $item) { | |
$productIds[] = $item->getProductId(); | |
} | |
$cacheKey = spl_object_hash($quote); | |
if (!isset($this->_preloadedPrices[$cacheKey])) { | |
$this->_preloadedPrices[$cacheKey] = Mage::getResourceSingleton('catalogrule/rule') | |
->getRulePrices($date, $websiteId, $groupId, $productIds); | |
} | |
foreach ($this->_preloadedPrices[$cacheKey] as $productId => $price) { | |
$key = implode('|', array($date, $websiteId, $groupId, $productId)); | |
$this->_rulePrices[$key] = $price; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment