Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable Class Reference

Inheritance diagram for Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 saveProducts ($mainProductId, $productIds)
 getChildrenIds ($parentId, $required=true)
 getParentIdsByChild ($childId)

Protected Member Functions

 _construct ()


Detailed Description

Definition at line 34 of file Configurable.php.


Member Function Documentation

_construct (  )  [protected]

Init resource

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 40 of file Configurable.php.

00041     {
00042         $this->_init('catalog/product_super_link', 'link_id');
00043     }

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 76 of file Configurable.php.

00077     {
00078         $childrenIds = array();
00079         $select = $this->_getReadAdapter()->select()
00080             ->from(array('l' => $this->getMainTable()), array('product_id', 'parent_id'))
00081             ->join(
00082                 array('e' => $this->getTable('catalog/product')),
00083                 'e.entity_id=l.product_id AND e.required_options=0',
00084                 array()
00085             )
00086             ->where('parent_id=?', $parentId);
00087 
00088         $childrenIds = array(0 => array());
00089         foreach ($this->_getReadAdapter()->fetchAll($select) as $row) {
00090             $childrenIds[0][$row['product_id']] = $row['product_id'];
00091         }
00092 
00093         return $childrenIds;
00094     }

getParentIdsByChild ( childId  ) 

Retrieve parent ids array by requered child

Parameters:
int|array $childId
Returns:
array

Definition at line 102 of file Configurable.php.

00103     {
00104         $parentIds = array();
00105 
00106         $select = $this->_getReadAdapter()->select()
00107             ->from($this->getMainTable(), array('product_id', 'parent_id'))
00108             ->where('product_id IN(?)', $childId);
00109         foreach ($this->_getReadAdapter()->fetchAll($select) as $row) {
00110             $parentIds[] = $row['parent_id'];
00111         }
00112 
00113         return $parentIds;
00114     }

saveProducts ( mainProductId,
productIds 
)

Save product

Parameters:
int $mainProductId the parent id
array $productIds the children id array
Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable

Definition at line 52 of file Configurable.php.

00053     {
00054         $this->_getWriteAdapter()->delete($this->getMainTable(),
00055             $this->_getWriteAdapter()->quoteInto('parent_id=?', $mainProductId)
00056         );
00057         foreach ($productIds as $productId) {
00058             $this->_getWriteAdapter()->insert($this->getMainTable(), array(
00059                'product_id'    => $productId,
00060                'parent_id'     => $mainProductId
00061             ));
00062         }
00063         return $this;
00064     }


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

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