Mage_CatalogRule_Model_Observer Class Reference

List of all members.

Public Member Functions

 applyAllRulesOnProduct ($observer)
 applyAllRules ($observer)
 processFrontFinalPrice ($observer)
 processAdminFinalPrice ($observer)
 dailyCatalogUpdate ($observer)
 flushPriceCache ()

Protected Attributes

 $_rulePrices = array()


Detailed Description

Catalog Price rules observer model

Definition at line 30 of file Observer.php.


Member Function Documentation

applyAllRules ( observer  ) 

Apply all price rules for current date

Parameters:
Varien_Event_Observer $observer
Returns:
Mage_CatalogRule_Model_Observer

Definition at line 70 of file Observer.php.

00071     {
00072         $resource = Mage::getResourceSingleton('catalogrule/rule');
00073         $resource->applyAllRulesForDateRange($resource->formatDate(mktime(0,0,0)));
00074         Mage::app()->removeCache('catalog_rules_dirty');
00075         return $this;
00076     }

applyAllRulesOnProduct ( observer  ) 

Apply all catalog price rules for specific product

Parameters:
Varien_Event_Observer $observer
Returns:
Mage_CatalogRule_Model_Observer

Definition at line 40 of file Observer.php.

00041     {
00042         $product = $observer->getEvent()->getProduct();
00043         if ($product->getIsMassupdate()) {
00044             return;
00045         }
00046 
00047         $productWebsiteIds = $product->getWebsiteIds();
00048 
00049         $rules = Mage::getModel('catalogrule/rule')->getCollection()
00050             ->addFieldToFilter('is_active', 1);
00051 
00052         foreach ($rules as $rule) {
00053             if (!is_array($rule->getWebsiteIds())) {
00054                 $ruleWebsiteIds = (array)explode(',', $rule->getWebsiteIds());
00055             } else {
00056                 $ruleWebsiteIds = $rule->getWebsiteIds();
00057             }
00058             $websiteIds = array_intersect($productWebsiteIds, $ruleWebsiteIds);
00059             $rule->applyToProduct($product, $websiteIds);
00060         }
00061         return $this;
00062     }

dailyCatalogUpdate ( observer  ) 

Daily update catalog price rule by cron Update include interval 3 days - current day - 1 days before + 1 days after This method is called from cron process, cron is workink in UTC time and we shold generate data for interval -1 day ... +1 day

Parameters:
Varien_Event_Observer $observer
Returns:
Mage_CatalogRule_Model_Observer

Definition at line 169 of file Observer.php.

00170     {
00171         Mage::getResourceSingleton('catalogrule/rule')->applyAllRulesForDateRange();
00172         return $this;
00173     }

flushPriceCache (  ) 

Definition at line 175 of file Observer.php.

00176     {
00177         $this->_rulePrices = array();
00178     }

processAdminFinalPrice ( observer  ) 

Apply catalog price rules to product in admin

Returns:
Mage_CatalogRule_Model_Observer

Definition at line 125 of file Observer.php.

00126     {
00127         $product = $observer->getEvent()->getProduct();
00128         $storeId = $product->getStoreId();
00129         $date = Mage::app()->getLocale()->storeDate($storeId);
00130         $key = false;
00131 
00132         if ($ruleData = Mage::registry('rule_data')) {
00133             $wId = $ruleData->getWebsiteId();
00134             $gId = $ruleData->getCustomerGroupId();
00135             $pId = $product->getId();
00136 
00137             $key = "$date|$wId|$gId|$pId";
00138         }
00139         elseif ($product->getWebsiteId() != null && $product->getCustomerGroupId() != null) {
00140             $wId = $product->getWebsiteId();
00141             $gId = $product->getCustomerGroupId();
00142             $pId = $product->getId();
00143             $key = "$date|$wId|$gId|$pId";
00144         }
00145 
00146         if ($key) {
00147             if (!isset($this->_rulePrices[$key])) {
00148                 $rulePrice = Mage::getResourceModel('catalogrule/rule')
00149                     ->getRulePrice($date, $wId, $gId, $pId);
00150                 $this->_rulePrices[$key] = $rulePrice;
00151             }
00152             if ($this->_rulePrices[$key]!==false) {
00153                 $finalPrice = min($product->getData('final_price'), $this->_rulePrices[$key]);
00154                 $product->setFinalPrice($finalPrice);
00155             }
00156         }
00157         return $this;
00158     }

processFrontFinalPrice ( observer  ) 

Apply catalog price rules to product on frontend

Returns:
Mage_CatalogRule_Model_Observer

Definition at line 83 of file Observer.php.

00084     {
00085         $product    = $observer->getEvent()->getProduct();
00086         $pId        = $product->getId();
00087         $storeId    = $product->getStoreId();
00088 
00089         if ($observer->hasDate()) {
00090             $date = $observer->getDate();
00091         } else {
00092             $date = Mage::app()->getLocale()->storeTimeStamp($storeId);
00093         }
00094 
00095         if ($observer->hasWebsiteId()) {
00096             $wId = $observer->getWebsiteId();
00097         } else {
00098             $wId = Mage::app()->getStore($storeId)->getWebsiteId();
00099         }
00100 
00101         if ($observer->hasCustomerGroupId()) {
00102             $gId = $observer->getCustomerGroupId();
00103         } else {
00104             $gId = Mage::getSingleton('customer/session')->getCustomerGroupId();
00105         }
00106 
00107         $key = "$date|$wId|$gId|$pId";
00108         if (!isset($this->_rulePrices[$key])) {
00109             $rulePrice = Mage::getResourceModel('catalogrule/rule')
00110                 ->getRulePrice($date, $wId, $gId, $pId);
00111             $this->_rulePrices[$key] = $rulePrice;
00112         }
00113         if ($this->_rulePrices[$key]!==false) {
00114             $finalPrice = min($product->getData('final_price'), $this->_rulePrices[$key]);
00115             $product->setFinalPrice($finalPrice);
00116         }
00117         return $this;
00118     }


Member Data Documentation

$_rulePrices = array() [protected]

Definition at line 32 of file Observer.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:48 2009 for Magento by  doxygen 1.5.8