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 class Mage_Bundle_Model_Price_Index extends Mage_Core_Model_Abstract
00036 {
00037
00038
00039
00040
00041 protected function _construct()
00042 {
00043 $this->_init('bundle/price_index');
00044 }
00045
00046
00047
00048
00049
00050
00051 protected function _getResource()
00052 {
00053 return parent::_getResource();
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063 protected function _reindexProduct($productId, $priceType)
00064 {
00065 $this->_getResource()->reindexProduct($productId, $priceType);
00066 return $this;
00067 }
00068
00069
00070
00071
00072
00073
00074
00075 public function reindex($products = null)
00076 {
00077 $this->_getResource()->reindex($products);
00078 return $this;
00079 }
00080
00081
00082
00083
00084
00085
00086
00087 public function addPriceIndexToCollection($collection)
00088 {
00089 $productObjects = array();
00090 $productIds = array();
00091 foreach ($collection->getItems() as $product) {
00092
00093 if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
00094 $productIds[] = $product->getEntityId();
00095 $productObjects[$product->getEntityId()] = $product;
00096 }
00097 }
00098 $websiteId = Mage::app()->getStore($collection->getStoreId())
00099 ->getWebsiteId();
00100 $groupId = Mage::getSingleton('customer/session')
00101 ->getCustomerGroupId();
00102
00103 $addOptionsToResult = false;
00104 $prices = $this->_getResource()->loadPriceIndex($productIds, $websiteId, $groupId);
00105 foreach ($productIds as $productId) {
00106 if (isset($prices[$productId])) {
00107 $productObjects[$productId]
00108 ->setData('_price_index', true)
00109 ->setData('_price_index_min_price', $prices[$productId]['min_price'])
00110 ->setData('_price_index_max_price', $prices[$productId]['max_price']);
00111 }
00112 else {
00113 $addOptionsToResult = true;
00114 }
00115 }
00116
00117 if ($addOptionsToResult) {
00118 $collection->addOptionsToResult();
00119 }
00120
00121 return $this;
00122 }
00123
00124
00125
00126
00127
00128
00129
00130 public function addPriceIndexToProduct($product)
00131 {
00132 $websiteId = $product->getStore()->getWebsiteId();
00133 $groupId = Mage::getSingleton('customer/session')
00134 ->getCustomerGroupId();
00135 $prices = $this->_getResource()
00136 ->loadPriceIndex($product->getId(), $websiteId, $groupId);
00137 if (isset($prices[$product->getId()])) {
00138 $product->setData('_price_index', true)
00139 ->setData('_price_index_min_price', $prices[$product->getId()]['min_price'])
00140 ->setData('_price_index_max_price', $prices[$product->getId()]['max_price']);
00141 }
00142 return $this;
00143 }
00144 }