00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 class Mage_Sales_Model_Entity_Quote_Item_Collection extends Mage_Eav_Model_Entity_Collection_Abstract
00037 {
00038
00039
00040
00041
00042
00043 protected $_quote;
00044
00045 protected function _construct()
00046 {
00047 $this->_init('sales/quote_item');
00048 }
00049
00050 public function getStoreId()
00051 {
00052 return $this->_quote->getStoreId();
00053 }
00054
00055 public function setQuote($quote)
00056 {
00057 $this->_quote = $quote;
00058 $this->addAttributeToFilter('parent_id', $quote->getId());
00059 return $this;
00060 }
00061
00062 protected function _afterLoad()
00063 {
00064 Varien_Profiler::start('TEST1: '.__METHOD__);
00065 $productCollection = $this->_getProductCollection();
00066 Varien_Profiler::stop('TEST1: '.__METHOD__);
00067 $recollectQuote = false;
00068 foreach ($this as $item) {
00069 Varien_Profiler::start('TEST2: '.__METHOD__);
00070 if ($productCollection) {
00071 $product = $productCollection->getItemById($item->getProductId());
00072 } else {
00073 $product = false;
00074 }
00075 if ($this->_quote) {
00076 $item->setQuote($this->_quote);
00077 }
00078 if (!$product) {
00079 $item->isDeleted(true);
00080 $recollectQuote = true;
00081 continue;
00082 }
00083
00084 if ($item->getSuperProductId()) {
00085 $superProduct = $productCollection->getItemById($item->getSuperProductId());
00086 if (!$superProduct) {
00087 $item->isDeleted(true);
00088 $recollectQuote = true;
00089 continue;
00090 }
00091 }
00092 else {
00093 $superProduct = null;
00094 }
00095
00096 $itemProduct = clone $product;
00097 if ($superProduct) {
00098 $itemProduct->setSuperProduct($superProduct);
00099 $item->setSuperProduct($superProduct);
00100 }
00101
00102 $item->importCatalogProduct($itemProduct);
00103 $item->checkData();
00104 Varien_Profiler::stop('TEST2: '.__METHOD__);
00105 }
00106 if ($recollectQuote && $this->_quote) {
00107 $this->_quote->collectTotals();
00108 }
00109 return $this;
00110 }
00111
00112 protected function _getProductCollection()
00113 {
00114 $productIds = array();
00115 foreach ($this as $item) {
00116 $productIds[$item->getProductId()] = $item->getProductId();
00117 if ($item->getSuperProductId()) {
00118 $productIds[$item->getSuperProductId()] = $item->getSuperProductId();
00119 }
00120 if ($item->getParentProductId()) {
00121 $productIds[$item->getSuperProductId()] = $item->getParentProductId();
00122 }
00123 }
00124
00125 if (empty($productIds)) {
00126 return false;
00127 }
00128
00129 $collection = Mage::getModel('catalog/product')->getCollection()
00130 ->setStoreId($this->getStoreId())
00131 ->addIdFilter($productIds)
00132 ->addAttributeToSelect('*')
00133 ->addStoreFilter()
00134 ->addUrlRewrite();
00135
00136 if (Mage::app()->useCache('checkout_quote')) {
00137 $collection->initCache(
00138 $this->_getCacheInstance(),
00139 $this->_cacheConf['prefix'].'_PRODUCTS',
00140 $this->_getCacheTags()
00141 );
00142 }
00143
00144 return $collection;
00145 }
00146 }