Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link Class Reference

Inheritance diagram for Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 saveProductLinks ($product, $data, $typeId)
 getAttributesByType ($typeId)
 getAttributeTypeTable ($type)
 getChildrenIds ($parentId, $typeId)
 getParentIdsByChild ($childId, $typeId)

Protected Member Functions

 _construct ()

Protected Attributes

 $_attributesTable


Detailed Description

Definition at line 35 of file Link.php.


Member Function Documentation

_construct (  )  [protected]

Resource initialization

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 38 of file Link.php.

00039     {
00040         $this->_init('catalog/product_link', 'link_id');
00041         $this->_attributesTable = $this->getTable('catalog/product_link_attribute');
00042     }

getAttributesByType ( typeId  ) 

Definition at line 76 of file Link.php.

00077     {
00078         $select = $this->_getReadAdapter()->select()
00079             ->from($this->_attributesTable, array(
00080                 'id'    => 'product_link_attribute_id',
00081                 'code'  => 'product_link_attribute_code',
00082                 'type'  => 'data_type'
00083             ))
00084             ->where('link_type_id=?', $typeId);
00085         return $this->_getReadAdapter()->fetchAll($select);
00086     }

getAttributeTypeTable ( type  ) 

Definition at line 88 of file Link.php.

00089     {
00090         return $this->getTable('catalog/product_link_attribute_'.$type);
00091     }

getChildrenIds ( parentId,
typeId 
)

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

Parameters:
int $parentId
int $typeId
Returns:
array

Definition at line 103 of file Link.php.

00104     {
00105         $childrenIds = array();
00106         $select = $this->_getReadAdapter()->select()
00107             ->from(array('l' => $this->getMainTable()), array('product_id', 'linked_product_id'))
00108             ->where('product_id=?', $parentId)
00109             ->where('link_type_id=?', $typeId);
00110         if ($typeId == Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED) {
00111             $select->join(
00112                 array('e' => $this->getTable('catalog/product')),
00113                 'e.entity_id=l.linked_product_id AND e.required_options=0',
00114                 array()
00115             );
00116         }
00117 
00118         $childrenIds[$typeId] = array();
00119         foreach ($this->_getReadAdapter()->fetchAll($select) as $row) {
00120             $childrenIds[$typeId][$row['linked_product_id']] = $row['linked_product_id'];
00121         }
00122 
00123         return $childrenIds;
00124     }

getParentIdsByChild ( childId,
typeId 
)

Retrieve parent ids array by requered child

Parameters:
int|array $childId
int $typeId
Returns:
array

Definition at line 133 of file Link.php.

00134     {
00135         $parentIds = array();
00136 
00137         $select = $this->_getReadAdapter()->select()
00138             ->from($this->getMainTable(), array('product_id', 'linked_product_id'))
00139             ->where('linked_product_id IN(?)', $childId)
00140             ->where('link_type_id=?', $typeId);
00141         foreach ($this->_getReadAdapter()->fetchAll($select) as $row) {
00142             $parentIds[] = $row['product_id'];
00143         }
00144 
00145         return $parentIds;
00146     }

saveProductLinks ( product,
data,
typeId 
)

Definition at line 44 of file Link.php.

00045     {
00046         if (!is_array($data)) {
00047             $data = array();
00048         }
00049         $attributes = $this->getAttributesByType($typeId);
00050         $deleteCondition = $this->_getWriteAdapter()->quoteInto('product_id=?', $product->getId())
00051             . $this->_getWriteAdapter()->quoteInto(' AND link_type_id=?', $typeId);
00052 
00053         $this->_getWriteAdapter()->delete($this->getMainTable(), $deleteCondition);
00054 
00055         foreach ($data as $linkedProductId => $linkInfo) {
00056             $this->_getWriteAdapter()->insert($this->getMainTable(), array(
00057                 'product_id'        => $product->getId(),
00058                 'linked_product_id' => $linkedProductId,
00059                 'link_type_id'      => $typeId
00060             ));
00061             $linkId = $this->_getWriteAdapter()->lastInsertId();
00062             foreach ($attributes as $attributeInfo) {
00063                 $attributeTable = $this->getAttributeTypeTable($attributeInfo['type']);
00064                 if ($attributeTable && isset($linkInfo[$attributeInfo['code']])) {
00065                     $this->_getWriteAdapter()->insert($attributeTable, array(
00066                         'product_link_attribute_id' => $attributeInfo['id'],
00067                         'link_id'                   => $linkId,
00068                         'value'                     => $linkInfo[$attributeInfo['code']]
00069                     ));
00070                 }
00071             }
00072         }
00073         return $this;
00074     }


Member Data Documentation

$_attributesTable [protected]

Definition at line 37 of file Link.php.


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

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