00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Sales 00023 * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 00028 /** 00029 * Sales observer 00030 * 00031 * @category Mage 00032 * @package Mage_Sales 00033 * @author Magento Core Team <core@magentocommerce.com> 00034 */ 00035 class Mage_Sales_Model_Observer 00036 { 00037 /** 00038 * Clean expired quotes (cron process) 00039 * 00040 * @param Mage_Cron_Model_Schedule $schedule 00041 * @return Mage_Sales_Model_Observer 00042 */ 00043 public function cleanExpiredQuotes($schedule) 00044 { 00045 $lifetimes = Mage::getConfig()->getStoresConfigByPath('checkout/cart/delete_quote_after'); 00046 foreach ($lifetimes as $storeId=>$lifetime) { 00047 $lifetime *= 86400; 00048 00049 $quotes = Mage::getModel('sales/quote')->getCollection(); 00050 /* @var $quotes Mage_Sales_Model_Mysql4_Quote_Collection */ 00051 00052 $quotes->addFieldToFilter('store_id', $storeId); 00053 $quotes->addFieldToFilter('updated_at', array('to'=>date("Y-m-d", time()-$lifetime))); 00054 $quotes->addFieldToFilter('is_active', 0); 00055 $quotes->walk('delete'); 00056 } 00057 return $this; 00058 } 00059 00060 /** 00061 * When deleting product, substract it from all quotes quantities 00062 * 00063 * @throws Exception 00064 * @param Varien_Event_Observer 00065 * @return Mage_Sales_Model_Observer 00066 */ 00067 public function substractQtyFromQuotes($observer) 00068 { 00069 $product = $observer->getEvent()->getProduct(); 00070 Mage::getResourceSingleton('sales/quote')->substractProductFromQuotes($product); 00071 return $this; 00072 } 00073 00074 /** 00075 * When applying a catalog price rule, make related quotes recollect on demand 00076 * 00077 * @param Varien_Event_Observer $observer 00078 * @return Mage_Sales_Model_Observer 00079 */ 00080 public function markQuotesRecollectOnCatalogRules($observer) 00081 { 00082 Mage::getResourceSingleton('sales/quote')->markQuotesRecollectOnCatalogRules(); 00083 return $this; 00084 } 00085 00086 /** 00087 * Catalog Product After Save (change status process) 00088 * 00089 * @param Varien_Event_Observer $observer 00090 * @return Mage_Sales_Model_Observer 00091 */ 00092 public function catalogProductSaveAfter(Varien_Event_Observer $observer) 00093 { 00094 $product = $observer->getEvent()->getProduct(); 00095 if ($product->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) { 00096 return $this; 00097 } 00098 00099 Mage::getResourceSingleton('sales/quote')->markQuotesRecollect($product->getId()); 00100 00101 return $this; 00102 } 00103 00104 /** 00105 * Catalog Mass Status update process 00106 * 00107 * @param Varien_Event_Observer $observer 00108 * @return Mage_Sales_Model_Observer 00109 */ 00110 public function catalogProductStatusUpdate(Varien_Event_Observer $observer) 00111 { 00112 $status = $observer->getEvent()->getStatus(); 00113 if ($status == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) { 00114 return $this; 00115 } 00116 $productId = $observer->getEvent()->getProductId(); 00117 Mage::getResourceSingleton('sales/quote')->markQuotesRecollect($productId); 00118 00119 return $this; 00120 } 00121 }