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 class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable extends Mage_Core_Model_Mysql4_Abstract
00035 {
00036
00037
00038
00039
00040 protected function _construct()
00041 {
00042 $this->_init('catalog/product_super_link', 'link_id');
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052 public function saveProducts($mainProductId, $productIds)
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 }
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 public function getChildrenIds($parentId, $required = true)
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 }
00095
00096
00097
00098
00099
00100
00101
00102 public function getParentIdsByChild($childId)
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 }
00115 }