Mage_Bundle_Model_Mysql4_Price_Index Class Reference

Inheritance diagram for Mage_Bundle_Model_Mysql4_Price_Index:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 getProducts ($product=null, $lastEntityId=0, $limit=100)
 reindex ($products=null)
 getSelections ($productId)
 getProductsSalableStatus ($products, Mage_Core_Model_Website $website)
 getProductsPriceFromIndex ($productIds)
 getProductsPriceData ($products, Mage_Core_Model_Website $website)
 getCustomOptions ($productId, Mage_Core_Model_Website $website)
 _calculateCustomOptions (array $options, $basePrice, $minPrice, $maxPrice)
 _calculateBundleSelections (array $options, array $salableStatus, $productId, $priceType, $basePrice, $priceData, $priceIndex, $website, $group)
 _calculateSpecialPrice ($finalPrice, array $priceData, Mage_Core_Model_Website $website)
 loadPriceIndex ($productIds, $websiteId, $groupId)

Protected Member Functions

 _construct ()
 _getAttribute ($attributeCode)
 _getWebsites ()
 _getCustomerGroups ()
 _reindexProduct ($productId, $priceType)
 _savePriceIndex ($productId, $websiteId, $groupId, $minPrice, $maxPrice)
 _addAttributeDataToSelect (Varien_Db_Select $select, $attributeCode, Mage_Core_Model_Website $website)
 _getBasePrice ($productId, array $priceData, $website, $customerGroup)

Protected Attributes

 $_attributes = array()
 $_websites
 $_customerGroups


Detailed Description

Definition at line 35 of file Index.php.


Member Function Documentation

_addAttributeDataToSelect ( Varien_Db_Select select,
attributeCode,
Mage_Core_Model_Website website 
) [protected]

Add attribute data to select

Parameters:
Varien_Db_Select $select
string $attributeCode
Mage_Core_Model_Website $website
Returns:
Mage_Bundle_Model_Mysql4_Price_Index

Definition at line 438 of file Index.php.

00439     {
00440         $attribute  = $this->_getAttribute($attributeCode);
00441         $store      = $website->getDefaultStore();
00442         if ($attribute->isScopeGlobal()) {
00443             $table = 't_' . $attribute->getAttributeCode();
00444             $select->joinLeft(
00445                 array($table => $attribute->getBackend()->getTable()),
00446                 'e.entity_id='.$table.'.entity_id'
00447                     . ' AND '.$table.'.attribute_id=' . $attribute->getAttributeId()
00448                     . ' AND '.$table.'.store_id=0',
00449                 array($attribute->getAttributeCode() => $table . '.value'));
00450         }
00451         else {
00452             $tableName   = $attribute->getBackend()->getTable();
00453             $tableGlobal = 't1_' . $attribute->getAttributeCode();
00454             $tableStore  = 't2_' . $attribute->getAttributeCode();
00455 
00456             $select->joinLeft(
00457                     array($tableGlobal => $tableName),
00458                     'e.entity_id='.$tableGlobal.'.entity_id'
00459                         . ' AND '.$tableGlobal.'.attribute_id=' . $attribute->getAttributeId()
00460                         . ' AND '.$tableGlobal.'.store_id=0',
00461                     array($attribute->getAttributeCode() => 'IFNULL('.$tableStore.'.value, '.$tableGlobal.'.value)'))
00462                 ->joinLeft(
00463                     array($tableStore => $tableName),
00464                     $tableGlobal.'.entity_id = '.$tableStore.'.entity_id'
00465                         . ' AND '.$tableGlobal.'.attribute_id = '.$tableStore.'.attribute_id'
00466                         . ' AND '.$tableStore.'.store_id=' . $store->getId(),
00467                     array());
00468         }
00469         return $this;
00470     }

_calculateBundleSelections ( array options,
array salableStatus,
productId,
priceType,
basePrice,
priceData,
priceIndex,
website,
group 
)

Calculate minimal and maximal price for bundle selections Return array with prices (0 -> min_price, 1 -> max_price)

Parameters:
array $options
array $salableStatus
int $productId
int $priceType
float $basePrice
array $priceData
array $priceIndex
Mage_Core_Model_Website $website
Mage_Customer_Model_Group $group
Returns:
array

Definition at line 673 of file Index.php.

00675     {
00676         $minPrice = $maxPrice = $basePrice;
00677 
00678         foreach ($options as $option) {
00679             $optionPrices = array();
00680             foreach ($option['selections'] as $selection) {
00681                 if (!$selection['product_id']) {
00682                     continue;
00683                 }
00684 
00685                 if (!$salableStatus[$selection['product_id']]) {
00686                     continue;
00687                 }
00688 
00689                 if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) {
00690                     $basePrice = $this->_getBasePrice($productId, $priceData, $website, $group);
00691                 }
00692 
00693                 // calculate selection price
00694                 if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) {
00695                     $priceIndexKey = join('-', array(
00696                         $selection['product_id'],
00697                         $website->getId(),
00698                         $group->getId()
00699                     ));
00700 
00701                     $selectionPrice = isset($priceIndex[$priceIndexKey]) ? $priceIndex[$priceIndexKey] : 0;
00702                     $selectionPrice = $this->_calculateSpecialPrice($selectionPrice, $priceData, $website);
00703                 }
00704                 else {
00705                     if ($selection['price_type']) { // persent
00706                         $selectionPrice = $basePrice * $selection['price_value'] / 100;
00707                     }
00708                     else {
00709                         $selectionPrice = $this->_calculateSpecialPrice($selection['price_value'], $priceData, $website);
00710                     }
00711                 }
00712 
00713                 // calculate selection qty
00714                 if ($selection['can_change_qty'] && $option['type'] != 'multi' && $option['type'] != 'checkbox') {
00715                     $qty = 1;
00716                 } else {
00717                     $qty = $selection['qty'];
00718                 }
00719 
00720                 $selectionPrice = $selectionPrice * $qty;
00721                 $optionPrices[$selection['selection_id']] = $selectionPrice;
00722             }
00723 
00724             if ($optionPrices) {
00725                 if ($option['required']) {
00726                     $minPrice += min($optionPrices);
00727                 }
00728                 if (in_array($option['type'], array('multi', 'checkbox'))) {
00729                     $maxPrice += array_sum($optionPrices);
00730                 }
00731                 else {
00732                     $maxPrice += max($optionPrices);
00733                 }
00734             }
00735         }
00736         return array($minPrice, $maxPrice);
00737     }

_calculateCustomOptions ( array options,
basePrice,
minPrice,
maxPrice 
)

Calculate custom options price Return array with indexes(0 -> min_price, 1 -> max_price)

Parameters:
array $options
float $basePrice
float $minPrice
float $maxPrice
Returns:
array

Definition at line 624 of file Index.php.

00625     {
00626         foreach ($options as $option) {
00627             $optionPrices = array();
00628             foreach ($option['values'] as $value) {
00629                 if ($value['price_type'] == 'percent') {
00630                     $valuePrice = $basePrice * $value['price_value'] / 100;;
00631                 }
00632                 else {
00633                     $valuePrice = $value['price_value'];
00634                 }
00635                 $optionPrices[] = $valuePrice;
00636             }
00637             if ($option['is_require']) {
00638                 $minPrice += min($optionPrices);
00639             }
00640             $multiTypes = array(
00641                 Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN,
00642                 Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX,
00643                 Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE
00644             );
00645             if ($optionPrices) {
00646                 if (in_array($option['type'], $multiTypes)) {
00647                     $maxPrice += array_sum($optionPrices);
00648                 }
00649                 else {
00650                     $maxPrice += max($optionPrices);
00651                 }
00652             }
00653         }
00654 
00655         return array($minPrice, $maxPrice);
00656     }

_calculateSpecialPrice ( finalPrice,
array priceData,
Mage_Core_Model_Website website 
)

Apply special price

Parameters:
float $finalPrice
array $priceData
Mage_Core_Model_Website $website
Returns:
float

Definition at line 747 of file Index.php.

00748     {
00749         $store              = $website->getDefaultStore();
00750         $specialPrice       = $priceData['special_price'];
00751 
00752         if (!is_null($specialPrice) && $specialPrice != false) {
00753             if (Mage::app()->getLocale()->IsStoreDateInInterval($store, $priceData['special_from_date'], $priceData['special_to_date'])) {
00754                 $specialPrice   = ($finalPrice * $specialPrice) / 100;
00755                 $finalPrice     = min($finalPrice, $specialPrice);
00756             }
00757         }
00758 
00759         return $finalPrice;
00760     }

_construct (  )  [protected]

Initialize connection and define main table

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 62 of file Index.php.

00063     {
00064         $this->_init('bundle/price_index', 'entity_id');
00065     }

_getAttribute ( attributeCode  )  [protected]

Retrieve attribute object

Parameters:
string $attributeCode
Returns:
Mage_Catalog_Model_Resource_Eav_Attribute

Definition at line 73 of file Index.php.

00074     {
00075         if (!isset($this->_attributes[$attributeCode])) {
00076             $this->_attributes[$attributeCode] = Mage::getSingleton('catalog/config')
00077                 ->getAttribute('catalog_product', $attributeCode);
00078         }
00079         return $this->_attributes[$attributeCode];
00080     }

_getBasePrice ( productId,
array priceData,
website,
customerGroup 
) [protected]

Retrieve fixed bundle base price (with special price and rules)

Parameters:
int $productId
array $priceData
Mage_Core_Model_Website $website
Mage_Customer_Model_Group $customerGroup
Returns:
float

Definition at line 481 of file Index.php.

00482     {
00483         $store          = $website->getDefaultStore();
00484         $storeTimeStamp = Mage::app()->getLocale()->storeTimeStamp($store);
00485         $finalPrice     = $this->_calculateSpecialPrice($priceData['price'], $priceData, $website);
00486 
00487         $rulePrice = Mage::getResourceModel('catalogrule/rule')
00488             ->getRulePrice($storeTimeStamp, $website->getId(), $customerGroup->getId(), $productId);
00489 
00490         if ($rulePrice !== null && $rulePrice !== false) {
00491             $finalPrice = min($finalPrice, $rulePrice);
00492         }
00493 
00494         return $finalPrice;
00495     }

_getCustomerGroups (  )  [protected]

Retrieve customer groups collection array

Returns:
array

Definition at line 100 of file Index.php.

00101     {
00102         if (is_null($this->_customerGroups)) {
00103             $this->_customerGroups = array();
00104             foreach (Mage::getModel('customer/group')->getCollection() as $group) {
00105                 $this->_customerGroups[$group->getId()] = $group;
00106             }
00107         }
00108         return $this->_customerGroups;
00109     }

_getWebsites (  )  [protected]

Retrieve websites collection array

Returns:
array

Definition at line 87 of file Index.php.

00088     {
00089         if (is_null($this->_websites)) {
00090             $this->_websites = Mage::app()->getWebsites(false);
00091         }
00092         return $this->_websites;
00093     }

_reindexProduct ( productId,
priceType 
) [protected]

Reindex product price

Parameters:
int $productId
int $priceType
Returns:
Mage_Bundle_Model_Mysql4_Price_Index

Definition at line 188 of file Index.php.

00189     {
00190         $options = $this->getSelections($productId);
00191         $selectionProducts = array();
00192         foreach ($options as $option) {
00193             foreach ($option['selections'] as $selection) {
00194                 $selectionProducts[$selection['product_id']] = $selection['product_id'];
00195             }
00196         }
00197 
00198         $priceIndex = array();
00199         if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) {
00200             // load selection product prices from index for dynamic bundle
00201             $priceIndex = $this->getProductsPriceFromIndex($selectionProducts);
00202         }
00203 
00204         foreach ($this->_getWebsites() as $website) {
00205             if (!$website->getDefaultStore()) {
00206                 continue;
00207             }
00208             $salableStatus = $this->getProductsSalableStatus($selectionProducts, $website);
00209             $priceData = $this->getProductsPriceData($productId, $website);
00210             $priceData = $priceData[$productId];
00211 
00212             /* @var $website Mage_Core_Model_Website */
00213             foreach ($this->_getCustomerGroups() as $group) {
00214                 /* @var $group Mage_Customer_Model_Group */
00215                 if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) {
00216                     $basePrice     = $this->_getBasePrice($productId, $priceData, $website, $group);
00217                     $customOptions = $this->getCustomOptions($productId, $website);
00218                 }
00219                 elseif ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) {
00220                     $basePrice = 0;
00221                 }
00222 
00223                 list($minPrice, $maxPrice) = $this->_calculateBundleSelections($options, $salableStatus,
00224                     $productId, $priceType, $basePrice, $priceData, $priceIndex, $website, $group);
00225 
00226                 if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) {
00227                     list($minPrice, $maxPrice) = $this->_calculateCustomOptions($customOptions, $basePrice, $minPrice, $maxPrice);
00228                 }
00229 
00230                 $this->_savePriceIndex($productId, $website->getId(), $group->getId(), $minPrice, $maxPrice);
00231             }
00232         }
00233 
00234         return $this;
00235     }

_savePriceIndex ( productId,
websiteId,
groupId,
minPrice,
maxPrice 
) [protected]

Save price index

Parameters:
int $productId
int $websiteId
int $groupId
float $minPrice
float $maxPrice
Returns:
Mage_Bundle_Model_Mysql4_Price_Index

Definition at line 247 of file Index.php.

00248     {
00249         $adapter = $this->_getWriteAdapter();
00250         $adapter->beginTransaction();
00251         $sql = sprintf('INSERT INTO %s VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE'
00252             . ' `min_price`=VALUES(`min_price`), `max_price`=VALUES(`max_price`)',
00253             $adapter->quoteIdentifier($this->getMainTable()));
00254         $bind = array($productId, $websiteId, $groupId, $minPrice, $maxPrice);
00255         $adapter->query($sql, $bind);
00256         $adapter->commit();
00257 
00258         return $this;
00259     }

getCustomOptions ( productId,
Mage_Core_Model_Website website 
)

Retrieve custom options for product

Parameters:
int $productId
Mage_Core_Model_Website $website
Returns:
array

Definition at line 504 of file Index.php.

00505     {
00506         $options = array();
00507         $store   = $website->getDefaultStore();
00508         $price   = $this->_getAttribute('price');
00509 
00510         $select = $this->getReadConnection()->select()
00511             ->from(
00512                 array('option_table' => $this->getTable('catalog/product_option')),
00513                 array('option_id', 'is_require', 'type'))
00514             ->where('option_table.product_id=?', $productId);
00515 
00516         if ($price->isScopeGlobal()) {
00517             $select->join(
00518                 array('price_table' => $this->getTable('catalog/product_option_price')),
00519                 'option_table.option_id=price_table.option_id'
00520                     . ' AND price_table.store_id=0',
00521                 array('value_id' => 'option_price_id', 'price', 'price_type')
00522             );
00523         }
00524         else {
00525             $select
00526                 ->join(
00527                     array('price_global_table' => $this->getTable('catalog/product_option_price')),
00528                     'option_table.option_id=price_global_table.option_id'
00529                         . ' AND price_global_table.store_id=0',
00530                     array(
00531                         'value_id'   => 'IFNULL(price_store_table.option_price_id, price_global_table.option_price_id)',
00532                         'price'      => 'IFNULL(price_store_table.price, price_global_table.price)',
00533                         'price_type' => 'IFNULL(price_store_table.price_type, price_global_table.price_type)'
00534                     ))
00535                 ->joinLeft(
00536                     array('price_store_table' => $this->getTable('catalog/product_option_price')),
00537                     'option_table.option_id=price_store_table.option_id'
00538                         . ' AND price_store_table.store_id=' . $store->getId(),
00539                     array());
00540         }
00541 
00542         $query = $this->_getReadAdapter()->query($select);
00543         while ($row = $query->fetch()) {
00544             if (!isset($options[$row['option_id']])) {
00545                 $options[$row['option_id']] = array(
00546                     'option_id'     => $row['option_id'],
00547                     'is_require'    => $row['is_require'],
00548                     'type'          => $row['type'],
00549                     'values'        => array()
00550                 );
00551             }
00552             $options[$row['option_id']]['values'][$row['value_id']] = array(
00553                 'price_type'        => $row['price_type'],
00554                 'price_value'       => $row['price']
00555             );
00556         }
00557 
00558         $select = $this->getReadConnection()->select()
00559             ->from(
00560                 array('option_table' => $this->getTable('catalog/product_option')),
00561                 array('option_id', 'is_require', 'type'))
00562             ->join(
00563                 array('type_table' => $this->getTable('catalog/product_option_type_value')),
00564                 'option_table.option_id=type_table.option_id',
00565                 array()
00566             )
00567             ->where('option_table.product_id=?', $productId);
00568 
00569         if ($price->isScopeGlobal()) {
00570             $select->join(
00571                 array('price_table' => $this->getTable('catalog/product_option_type_price')),
00572                 'type_table.option_type_id=price_table.option_type_id'
00573                     . ' AND price_table.store_id=0',
00574                 array('value_id' => 'option_type_id', 'price', 'price_type')
00575             );
00576         }
00577         else {
00578             $select
00579                 ->join(
00580                     array('price_global_table' => $this->getTable('catalog/product_option_type_price')),
00581                     'type_table.option_type_id=price_global_table.option_type_id'
00582                         . ' AND price_global_table.store_id=0',
00583                     array(
00584                         'value_id'   => 'IFNULL(price_store_table.option_type_id, price_global_table.option_type_id)',
00585                         'price'      => 'IFNULL(price_store_table.price, price_global_table.price)',
00586                         'price_type' => 'IFNULL(price_store_table.price_type, price_global_table.price_type)'
00587                     ))
00588                 ->joinLeft(
00589                     array('price_store_table' => $this->getTable('catalog/product_option_type_price')),
00590                     'type_table.option_type_id=price_store_table.option_type_id'
00591                         . ' AND price_store_table.store_id=' . $store->getId(),
00592                     array());
00593         }
00594 
00595         $query = $this->_getReadAdapter()->query($select);
00596         while ($row = $query->fetch()) {
00597             if (!isset($options[$row['option_id']])) {
00598                 $options[$row['option_id']] = array(
00599                     'option_id'     => $row['option_id'],
00600                     'is_require'    => $row['is_require'],
00601                     'type'          => $row['type'],
00602                     'values'        => array()
00603                 );
00604             }
00605             $options[$row['option_id']]['values'][$row['value_id']] = array(
00606                 'price_type'        => $row['price_type'],
00607                 'price_value'       => $row['price']
00608             );
00609         }
00610 
00611         return $options;
00612     }

getProducts ( product = null,
lastEntityId = 0,
limit = 100 
)

Retrieve product ids array by product condition

Parameters:
Mage_Core_Model_Product|Mage_Catalog_Model_Product_Condition_Interface|array|int $product
int $lastEntityId
int $limit
Returns:
array

Definition at line 119 of file Index.php.

00120     {
00121         $select = $this->_getReadAdapter()->select()
00122             ->from(
00123                 array('e' => $this->getTable('catalog/product')),
00124                 array('entity_id'))
00125             ->where('e.type_id=?', 'bundle');
00126         if ($product instanceof Mage_Core_Model_Product) {
00127             $select->where('e.entity_id=?', $product->getId());
00128         }
00129         elseif ($product instanceof Mage_Catalog_Model_Product_Condition_Interface) {
00130             $value = new Zend_Db_Expr($product->getIdsSelect($this->_getReadAdapter()));
00131             $select->where('e.entity_id IN(?)', $value);
00132         }
00133         elseif (is_numeric($product) || is_array($product)) {
00134             $select->where('e.entity_id IN(?)', $product);
00135         }
00136 
00137         $priceType = $this->_getAttribute('price_type');
00138         $priceTypeAlias = 't_' . $priceType->getAttributeCode();
00139         $joinConds = array(
00140             $this->_getReadAdapter()->quoteInto($priceTypeAlias . '.attribute_id=?', $priceType->getAttributeId()),
00141             $priceTypeAlias.'.store_id=0',
00142             $priceTypeAlias.'.entity_id=e.entity_id'
00143         );
00144         $select->joinLeft(
00145             array($priceTypeAlias => $priceType->getBackend()->getTable()),
00146             join(' AND ', $joinConds),
00147             array('price_type' => $priceTypeAlias . '.value')
00148         );
00149 
00150         $select->where('e.entity_id>?', $lastEntityId)
00151             ->order('e.entity_id')
00152             ->limit($limit);
00153 
00154         return $this->_getReadAdapter()->fetchPairs($select);
00155     }

getProductsPriceData ( products,
Mage_Core_Model_Website website 
)

Retrieve product(s) price data

Parameters:
int|array $products
Mage_Core_Model_Website $website
Returns:
array

Definition at line 405 of file Index.php.

00406     {
00407         $productsData = array();
00408         $select = $this->_getReadAdapter()->select()
00409             ->from(array('e' => $this->getTable('catalog/product')), 'entity_id')
00410             ->where('e.entity_id IN(?)', $products);
00411 
00412         $this->_addAttributeDataToSelect($select, 'price', $website);
00413         $this->_addAttributeDataToSelect($select, 'special_price', $website);
00414         $this->_addAttributeDataToSelect($select, 'special_from_date', $website);
00415         $this->_addAttributeDataToSelect($select, 'special_to_date', $website);
00416 
00417         $query = $this->_getReadAdapter()->query($select);
00418         while ($row = $query->fetch()) {
00419             $productsData[$row['entity_id']] = array(
00420                 'price'             => $row['price'],
00421                 'special_price'     => $row['special_price'],
00422                 'special_from_date' => $row['special_from_date'],
00423                 'special_to_date'   => $row['special_to_date']
00424             );
00425         }
00426 
00427         return $productsData;
00428     }

getProductsPriceFromIndex ( productIds  ) 

Retrieve Selection Product price from Price Index Return index key {entity_id}-{website_id}-{customer_group_id}

Parameters:
int|array $productIds
Returns:
array

Definition at line 376 of file Index.php.

00377     {
00378         $index  = array();
00379         $price  = $this->_getAttribute('price');
00380         $select = $this->_getReadAdapter()->select()
00381             ->from(
00382                 array('price_index' => $this->getTable('catalogindex/price')),
00383                 array('entity_id', 'customer_group_id', 'website_id', 'value'))
00384             ->where('entity_id IN(?)', $productIds)
00385             ->where('attribute_id=?', $price->getAttributeId());
00386         $query = $this->_getReadAdapter()->query($select);
00387         while ($row = $query->fetch()) {
00388             $indexKey = join('-', array(
00389                 $row['entity_id'],
00390                 $row['website_id'],
00391                 $row['customer_group_id']
00392             ));
00393             $index[$indexKey] = $row['value'];
00394         }
00395         return $index;
00396     }

getProductsSalableStatus ( products,
Mage_Core_Model_Website website 
)

Retrieve salable product statuses

Parameters:
int|array $products
Mage_Core_Model_Website $website
Returns:
array

Definition at line 311 of file Index.php.

00312     {
00313         $productsData = array();
00314         $select = $this->_getReadAdapter()->select()
00315             ->from(array('e' => $this->getTable('catalog/product')), 'entity_id')
00316             ->where('e.entity_id IN(?)', $products);
00317         // add belong to website
00318         $select->joinLeft(
00319             array('pw' => $this->getTable('catalog/product_website')),
00320             'e.entity_id=pw.product_id AND pw.website_id=' . $website->getId(),
00321             array('pw.website_id')
00322         );
00323 
00324         $store = $website->getDefaultStore();
00325 
00326         // add product status
00327         $status = $this->_getAttribute('status');
00328         if ($status->isScopeGlobal()) {
00329             $select->join(
00330                 array('t_status' => $status->getBackend()->getTable()),
00331                 'e.entity_id=t_status.entity_id'
00332                     . ' AND t_status.attribute_id=' . $status->getAttributeId()
00333                     . ' AND t_status.store_id=0',
00334                 array('status' => 't_status.value'));
00335         }
00336         else {
00337             $statusTable = $status->getBackend()->getTable();
00338             $select->join(
00339                     array('t1_status' => $statusTable),
00340                     'e.entity_id=t1_status.entity_id'
00341                         . ' AND t1_status.attribute_id=' . $status->getAttributeId()
00342                         . ' AND t1_status.store_id=0',
00343                     array('status' => 'IFNULL(t2_status.value, t1_status.value)'))
00344                 ->joinLeft(
00345                     array('t2_status' => $statusTable),
00346                     't1_status.entity_id = t2_status.entity_id'
00347                         . ' AND t1_status.attribute_id = t2_status.attribute_id'
00348                         . ' AND t2_status.store_id=' . $store->getId(),
00349                     array());
00350         }
00351 
00352         Mage::dispatchEvent('catalog_product_prepare_index_select', array(
00353             'website'   => $website,
00354             'select'    => $select
00355         ));
00356 
00357         $query = $this->_getReadAdapter()->query($select);
00358         while ($row = $query->fetch()) {
00359             $salable = isset($row['salable']) ? $row['salable'] : true;
00360             $website = $row['website_id'] > 0 ? true : false;
00361             $status  = $row['status'];
00362 
00363             $productsData[$row['entity_id']] = $salable && $status && $website;
00364         }
00365 
00366         return $productsData;
00367     }

getSelections ( productId  ) 

Retrieve bundle options with selections and prices by product

Parameters:
int $productId
Returns:
array

Definition at line 267 of file Index.php.

00268     {
00269         $options    = array();
00270         $select = $this->_getReadAdapter()->select()
00271             ->from(
00272                 array('option_table' => $this->getTable('bundle/option')),
00273                 array('option_id', 'required', 'type'))
00274             ->join(
00275                 array('selection_table' => $this->getTable('bundle/selection')),
00276                 'selection_table.option_id=option_table.option_id',
00277                 array('selection_id', 'product_id', 'selection_price_type',
00278                     'selection_price_value', 'selection_qty', 'selection_can_change_qty')
00279             )
00280             ->where('option_table.parent_id=?', $productId);
00281         $query = $this->_getReadAdapter()->query($select);
00282         while ($row = $query->fetch()) {
00283             if (!isset($options[$row['option_id']])) {
00284                 $options[$row['option_id']] = array(
00285                     'option_id'     => $row['option_id'],
00286                     'required'      => $row['required'],
00287                     'type'          => $row['type'],
00288                     'selections'    => array()
00289                 );
00290             }
00291             $options[$row['option_id']]['selections'][$row['selection_id']] = array(
00292                 'selection_id'      => $row['selection_id'],
00293                 'product_id'        => $row['product_id'],
00294                 'price_type'        => $row['selection_price_type'],
00295                 'price_value'       => $row['selection_price_value'],
00296                 'qty'               => $row['selection_qty'],
00297                 'can_change_qty'    => $row['selection_can_change_qty']
00298             );
00299         }
00300 
00301         return $options;
00302     }

loadPriceIndex ( productIds,
websiteId,
groupId 
)

Retrieve price index for products

Parameters:
int|array $productIds
int $websiteId
int $groupId
Returns:
array

Definition at line 770 of file Index.php.

00771     {
00772         $prices = array();
00773         $select = $this->_getReadAdapter()->select()
00774             ->from(
00775                 array('pi' => $this->getMainTable()),
00776                 array('entity_id', 'min_price', 'max_price'))
00777             ->where('entity_id IN(?)', $productIds)
00778             ->where('website_id=?', $websiteId)
00779             ->where('customer_group_id=?', $groupId);
00780         $query = $this->_getReadAdapter()->query($select);
00781         while ($row = $query->fetch()) {
00782             $prices[$row['entity_id']] = array(
00783                 'min_price' => $row['min_price'],
00784                 'max_price' => $row['max_price']
00785             );
00786         }
00787 
00788         return $prices;
00789     }

reindex ( products = null  ) 

Reindex Bundle product Price Index

Parameters:
Mage_Core_Model_Product|Mage_Catalog_Model_Product_Condition_Interface|array|int $products
Returns:
Mage_Bundle_Model_Price_Index

Definition at line 163 of file Index.php.

00164     {
00165         $lastEntityId = 0;
00166         while (true) {
00167             $productsData = $this->getProducts($products, $lastEntityId);
00168             if (!$productsData) {
00169                 break;
00170             }
00171 
00172             foreach ($productsData as $productId => $priceType) {
00173                 $this->_reindexProduct($productId, $priceType);
00174                 $lastEntityId = $productId;
00175             }
00176         }
00177 
00178         return $this;
00179     }


Member Data Documentation

$_attributes = array() [protected]

Definition at line 42 of file Index.php.

$_customerGroups [protected]

Definition at line 56 of file Index.php.

$_websites [protected]

Definition at line 49 of file Index.php.


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

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