Public Member Functions | |
loadGallery ($product, $object) | |
insertGallery ($data) | |
deleteGallery ($valueId) | |
insertGalleryValueInStore ($data) | |
deleteGalleryValueInStore ($valueId, $storeId) | |
duplicate ($object, $newFiles, $originalProductId, $newProductId) | |
Public Attributes | |
const | GALLERY_TABLE = 'catalog/product_attribute_media_gallery' |
const | GALLERY_VALUE_TABLE = 'catalog/product_attribute_media_gallery_value' |
const | GALLERY_IMAGE_TABLE = 'catalog/product_attribute_media_gallery_image' |
Protected Member Functions | |
_construct () | |
_removeDuplicates (&$result) |
Definition at line 34 of file Media.php.
_construct | ( | ) | [protected] |
Resource initialization
Reimplemented from Mage_Core_Model_Resource_Abstract.
Definition at line 43 of file Media.php.
00044 { 00045 $this->_init(self::GALLERY_TABLE, 'value_id'); 00046 }
_removeDuplicates | ( | &$ | result | ) | [protected] |
Definition at line 86 of file Media.php.
00087 { 00088 $fileToId = array(); 00089 00090 foreach (array_keys($result) as $index) { 00091 if (!isset($fileToId[$result[$index]['file']])) { 00092 $fileToId[$result[$index]['file']] = $result[$index]['value_id']; 00093 } elseif ($fileToId[$result[$index]['file']] != $result[$index]['value_id']) { 00094 $this->deleteGallery($result[$index]['value_id']); 00095 unset($result[$index]); 00096 } 00097 } 00098 00099 $result = array_values($result); 00100 return $this; 00101 }
deleteGallery | ( | $ | valueId | ) |
Delete gallery value in db
array|integer | $valueId |
Definition at line 121 of file Media.php.
00122 { 00123 if (is_array($valueId) && count($valueId)>0) { 00124 $condition = $this->_getWriteAdapter()->quoteInto('value_id IN(?) ', $valueId); 00125 } elseif (!is_array($valueId)) { 00126 $condition = $this->_getWriteAdapter()->quoteInto('value_id = ? ', $valueId); 00127 } else { 00128 return $this; 00129 } 00130 00131 $this->_getWriteAdapter()->delete($this->getMainTable(), $condition); 00132 return $this; 00133 }
deleteGalleryValueInStore | ( | $ | valueId, | |
$ | storeId | |||
) |
Delete gallery value for store in db
integer | $valueId | |
integer | $storeId |
Definition at line 154 of file Media.php.
00155 { 00156 $this->_getWriteAdapter()->delete( 00157 $this->getTable(self::GALLERY_VALUE_TABLE), 00158 'value_id = ' . (int)$valueId . ' AND store_id = ' . (int)$storeId 00159 ); 00160 00161 return $this; 00162 }
duplicate | ( | $ | object, | |
$ | newFiles, | |||
$ | originalProductId, | |||
$ | newProductId | |||
) |
Duplicates gallery db values
Mage_Catalog_Model_Product_Attribute_Backend_Media | $object | |
array | $newFiles | |
int | $originalProductId | |
int | $newProductId |
Definition at line 173 of file Media.php.
00174 { 00175 $select = $this->_getReadAdapter()->select() 00176 ->from($this->getMainTable(), array('value_id', 'value')) 00177 ->where('attribute_id = ?', $object->getAttribute()->getId()) 00178 ->where('entity_id = ?', $originalProductId); 00179 00180 $valueIdMap = array(); 00181 // Duplicate main entries of gallery 00182 foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { 00183 $data = array( 00184 'attribute_id' => $object->getAttribute()->getId(), 00185 'entity_id' => $newProductId, 00186 'value' => (isset($newFiles[$row['value_id']]) ? $newFiles[$row['value_id']] : $row['value']) 00187 ); 00188 00189 $valueIdMap[$row['value_id']] = $this->insertGallery($data); 00190 } 00191 00192 if (count($valueIdMap) == 0) { 00193 return $this; 00194 } 00195 00196 // Duplicate per store gallery values 00197 $select = $this->_getReadAdapter()->select() 00198 ->from($this->getTable(self::GALLERY_VALUE_TABLE)) 00199 ->where('value_id IN(?)', array_keys($valueIdMap)); 00200 00201 foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { 00202 $row['value_id'] = $valueIdMap[$row['value_id']]; 00203 $this->insertGalleryValueInStore($row); 00204 } 00205 00206 return $this; 00207 }
insertGallery | ( | $ | data | ) |
Insert gallery value to db and retrive last id
array | $data |
Definition at line 109 of file Media.php.
00110 { 00111 $this->_getWriteAdapter()->insert($this->getMainTable(), $data); 00112 return $this->_getWriteAdapter()->lastInsertId(); 00113 }
insertGalleryValueInStore | ( | $ | data | ) |
Insert gallery value for store to db
array | $data |
Definition at line 141 of file Media.php.
00142 { 00143 $this->_getWriteAdapter()->insert($this->getTable(self::GALLERY_VALUE_TABLE), $data); 00144 return $this; 00145 }
loadGallery | ( | $ | product, | |
$ | object | |||
) |
Load gallery images for product
Mage_Catalog_Model_Product | $product | |
Mage_Catalog_Model_Product_Attribute_Backend_Media | $object |
Definition at line 55 of file Media.php.
00056 { 00057 // Select gallery images for product 00058 $select = $this->_getReadAdapter()->select() 00059 ->from( 00060 array('main'=>$this->getMainTable()), 00061 array('value_id', 'value AS file') 00062 ) 00063 ->joinLeft( 00064 array('value'=>$this->getTable(self::GALLERY_VALUE_TABLE)), 00065 'main.value_id=value.value_id AND value.store_id='.(int)$product->getStoreId(), 00066 array('label','position','disabled') 00067 ) 00068 ->joinLeft( // Joining default values 00069 array('default_value'=>$this->getTable(self::GALLERY_VALUE_TABLE)), 00070 'main.value_id=default_value.value_id AND default_value.store_id=0', 00071 array( 00072 'label_default' => 'label', 00073 'position_default' => 'position', 00074 'disabled_default' => 'disabled' 00075 ) 00076 ) 00077 ->where('main.attribute_id = ?', $object->getAttribute()->getId()) 00078 ->where('main.entity_id = ?', $product->getId()) 00079 ->order('IF(value.position IS NULL, default_value.position, value.position) ASC'); 00080 00081 $result = $this->_getReadAdapter()->fetchAll($select); 00082 $this->_removeDuplicates($result); 00083 return $result; 00084 }
const GALLERY_IMAGE_TABLE = 'catalog/product_attribute_media_gallery_image' |
const GALLERY_TABLE = 'catalog/product_attribute_media_gallery' |
const GALLERY_VALUE_TABLE = 'catalog/product_attribute_media_gallery_value' |