public function testValidate() { $product = new Mage_Catalog_Model_Product(); $this->assertTrue($this->_model->validate($product)); $this->_model->getAttribute()->setIsRequired(true); try { $this->assertFalse($this->_model->validate($product)); $this->_model->getAttribute()->setIsRequired(false); } catch (Exception $e) { $this->_model->getAttribute()->setIsRequired(false); throw $e; } }
/** * Load gallery images for product * * @param Mage_Catalog_Model_Product $product * @param Mage_Catalog_Model_Product_Attribute_Backend_Media $object * @return array */ public function loadGallery($product, $object) { $adapter = $this->_getReadAdapter(); $positionCheckSql = $adapter->getCheckSql('value.position IS NULL', 'default_value.position', 'value.position'); // Select gallery images for product $select = $adapter->select()->from(array('main' => $this->getMainTable()), array('value_id', 'value AS file'))->joinLeft(array('value' => $this->getTable(self::GALLERY_VALUE_TABLE)), $adapter->quoteInto('main.value_id = value.value_id AND value.store_id = ?', (int) $product->getStoreId()), array('label', 'position', 'disabled'))->joinLeft(array('default_value' => $this->getTable(self::GALLERY_VALUE_TABLE)), 'main.value_id = default_value.value_id AND default_value.store_id = 0', array('label_default' => 'label', 'position_default' => 'position', 'disabled_default' => 'disabled', 'associated_attributes_default' => 'associated_attributes'))->where('main.attribute_id = ?', $object->getAttribute()->getId())->where('main.entity_id = ?', $product->getId())->order($positionCheckSql . ' ' . Varien_Db_Select::SQL_ASC); $result = $adapter->fetchAll($select); $this->_removeDuplicates($result); return $result; }
/** * Duplicates gallery db values * * @param Mage_Catalog_Model_Product_Attribute_Backend_Media $object * @param array $newFiles * @param int $originalProductId * @param int $newProductId * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media */ public function duplicate($object, $newFiles, $originalProductId, $newProductId) { $select = $this->_getReadAdapter()->select()->from($this->getMainTable(), array('value_id', 'value'))->where('attribute_id = ?', $object->getAttribute()->getId())->where('entity_id = ?', $originalProductId); $valueIdMap = array(); // Duplicate main entries of gallery foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { $data = array('attribute_id' => $object->getAttribute()->getId(), 'entity_id' => $newProductId, 'value' => isset($newFiles[$row['value_id']]) ? $newFiles[$row['value_id']] : $row['value']); $valueIdMap[$row['value_id']] = $this->insertGallery($data); } if (count($valueIdMap) == 0) { return $this; } // Duplicate per store gallery values $select = $this->_getReadAdapter()->select()->from($this->getTable(self::GALLERY_VALUE_TABLE))->where('value_id IN(?)', array_keys($valueIdMap)); foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { $row['value_id'] = $valueIdMap[$row['value_id']]; $this->insertGalleryValueInStore($row); } return $this; }
/** * Load gallery images for product * * @param Mage_Catalog_Model_Product $product * @param Mage_Catalog_Model_Product_Attribute_Backend_Media $object * @return array */ public function loadGallery($product, $object) { // Select gallery images for product $select = $this->_getReadAdapter()->select()->from(array('main' => $this->getMainTable()), array('value_id', 'value AS file'))->joinLeft(array('value' => $this->getTable(self::GALLERY_VALUE_TABLE)), 'main.value_id=value.value_id AND value.store_id=' . (int) $product->getStoreId(), array('label', 'position', 'disabled'))->joinLeft(array('default_value' => $this->getTable(self::GALLERY_VALUE_TABLE)), 'main.value_id=default_value.value_id AND default_value.store_id=0', array('label_default' => 'label', 'position_default' => 'position', 'disabled_default' => 'disabled'))->where('main.attribute_id = ?', $object->getAttribute()->getId())->where('main.entity_id = ?', $product->getId())->order('IF(value.position IS NULL, default_value.position, value.position) ASC'); return $this->_getReadAdapter()->fetchAll($select); }