Mage_Bundle_Model_Mysql4_Selection Class Reference

Inheritance diagram for Mage_Bundle_Model_Mysql4_Selection:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 getPriceFromIndex ($productId, $qty, $storeId, $groupId)
 getChildrenIds ($parentId, $required=true)
 getParentIdsByChild ($childId)

Protected Member Functions

 _construct ()


Detailed Description

Definition at line 34 of file Selection.php.


Member Function Documentation

_construct (  )  [protected]

Resource initialization

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 36 of file Selection.php.

00037     {
00038         $this->_init('bundle/selection', 'selection_id');
00039     }

getChildrenIds ( parentId,
required = true 
)

Retrieve Required children ids Return grouped array, ex array( group => array(ids) )

Parameters:
int $parentId
bool $required
Returns:
array

Definition at line 115 of file Selection.php.

00116     {
00117         $childrenIds = array();
00118         $notRequired = array();
00119         $select = $this->_getReadAdapter()->select()
00120             ->from(
00121                 array('tbl_selection' => $this->getMainTable()),
00122                 array('product_id', 'parent_product_id', 'option_id'))
00123             ->join(
00124                 array('e' => $this->getTable('catalog/product')),
00125                 'e.entity_id=tbl_selection.product_id AND e.required_options=0',
00126                 array()
00127             )
00128             ->join(
00129                 array('tbl_option' => $this->getTable('bundle/option')),
00130                 '`tbl_option`.`option_id` = `tbl_selection`.`option_id`',
00131                 array('required')
00132             )
00133             ->where('`tbl_selection`.`parent_product_id`=?', $parentId);
00134         foreach ($this->_getReadAdapter()->fetchAll($select) as $row) {
00135             if ($row['required']) {
00136                 $childrenIds[$row['option_id']][$row['product_id']] = $row['product_id'];
00137             }
00138             else {
00139                 $notRequired[$row['option_id']][$row['product_id']] = $row['product_id'];
00140             }
00141         }
00142 
00143         if (!$required) {
00144             $childrenIds = array_merge($childrenIds, $notRequired);
00145         }
00146         else {
00147             if (!$childrenIds) {
00148                 foreach ($notRequired as $groupedChildrenIds) {
00149                     foreach ($groupedChildrenIds as $childId) {
00150                         $childrenIds[0][$childId] = $childId;
00151                     }
00152                 }
00153             }
00154         }
00155 
00156         return $childrenIds;
00157     }

getParentIdsByChild ( childId  ) 

Retrieve parent ids array by requered child

Parameters:
int|array $childId
Returns:
array

Definition at line 165 of file Selection.php.

00166     {
00167         $parentIds = array();
00168 
00169         $select = $this->_getReadAdapter()->select()
00170             ->from(
00171                 array('tbl_selection' => $this->getMainTable()),
00172                 array('product_id', 'parent_product_id', 'option_id'))
00173             ->join(
00174                 array('tbl_option' => $this->getTable('bundle/option')),
00175                 '`tbl_option`.`option_id` = `tbl_selection`.`option_id`',
00176                 array('required')
00177             )
00178             ->where('`tbl_selection`.`product_id` IN(?)', $childId);
00179         foreach ($this->_getReadAdapter()->fetchAll($select) as $row) {
00180             $parentIds[] = $row['parent_product_id'];
00181         }
00182 
00183         return $parentIds;
00184     }

getPriceFromIndex ( productId,
qty,
storeId,
groupId 
)

Retrieve Price From index

Parameters:
int $productId
float $qty
int $storeId
int $groupId
Returns:
mixed

Definition at line 80 of file Selection.php.

00080                                                                             {
00081         $select = clone $this->_getReadAdapter()->select();
00082         $select->reset();
00083 
00084         $attrPriceId = Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', 'price');
00085         $attrTierPriceId = Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', 'tier_price');
00086 
00087         $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
00088 
00089         $select->from(array("price_index" => $this->getTable('catalogindex/price')), array('price' => 'SUM(value)'))
00090             ->where('entity_id in (?)', $productId)
00091             ->where('website_id = ?', $websiteId)
00092             ->where('customer_group_id = ?', $groupId)
00093             ->where('attribute_id in (?)', array($attrPriceId, $attrTierPriceId))
00094             ->where('qty <= ?', $qty)
00095             ->group('entity_id');
00096 
00097         $price = $this->_getReadAdapter()->fetchCol($select);
00098         if (!empty($price)) {
00099             return array_shift($price);
00100         } else {
00101             return 0;
00102         }
00103     }


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