/** * Insert entity attribute value * * @param Varien_Object $object * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute * @param mixed $value * @return Mage_Catalog_Model_Resource_Abstract */ protected function _insertAttribute($object, $attribute, $value) { /** * save required attributes in global scope every time if store id different from default */ $storeId = (int) Mage::app()->getStore($object->getStoreId())->getId(); if ($attribute->getIsRequired() && $this->getDefaultStoreId() != $storeId) { $table = $attribute->getBackend()->getTable(); $select = $this->_getReadAdapter()->select()->from($table)->where('entity_type_id = ?', $attribute->getEntityTypeId())->where('attribute_id = ?', $attribute->getAttributeId())->where('store_id = ?', $this->getDefaultStoreId())->where('entity_id = ?', $object->getEntityId()); $row = $this->_getReadAdapter()->fetchOne($select); if (!$row) { $data = new Varien_Object(array('entity_type_id' => $attribute->getEntityTypeId(), 'attribute_id' => $attribute->getAttributeId(), 'store_id' => $this->getDefaultStoreId(), 'entity_id' => $object->getEntityId(), 'value' => $this->_prepareValueForSave($value, $attribute))); $bind = $this->_prepareDataForTable($data, $table); $this->_getWriteAdapter()->insertOnDuplicate($table, $bind, array('value')); } } return $this->_saveAttributeValue($object, $attribute, $value); }
/** * Insert entity attribute value * * @param Varien_Object $object * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute * @param mixed $value * @return Mage_Eav_Model_Entity_Abstract */ protected function _insertAttribute($object, $attribute, $value) { /** * save required attributes in global scope every time if store id different from default */ $storeId = Mage::app()->getStore($object->getStoreId())->getId(); if ($attribute->getIsRequired() && $this->getDefaultStoreId() != $storeId) { $bind = array('entity_type_id' => $attribute->getEntityTypeId(), 'attribute_id' => $attribute->getAttributeId(), 'store_id' => $this->getDefaultStoreId(), 'entity_id' => $object->getEntityId(), 'value' => $this->_prepareValueForSave($value, $attribute)); $this->_getWriteAdapter()->insertOnDuplicate($attribute->getBackend()->getTable(), $bind, array('value')); } return $this->_saveAttributeValue($object, $attribute, $value); // $entityIdField = $attribute->getBackend()->getEntityIdField(); // $row = array( // $entityIdField => $object->getId(), // 'entity_type_id'=> $object->getEntityTypeId(), // 'attribute_id' => $attribute->getId(), // 'value' => $this->_prepareValueForSave($value, $attribute), // 'store_id' => $this->getDefaultStoreId() // ); // // $fields = array(); // $bind = array(); // foreach ($row as $k => $v) { // $fields[] = $this->_getWriteAdapter()->quoteIdentifier($k); // $bind[':' . $k] = $v; // } // // $sql = sprintf('INSERT IGNORE INTO %s (%s) VALUES(%s)', // $this->_getWriteAdapter()->quoteIdentifier($attribute->getBackend()->getTable()), // implode(',', $fields), // implode(',', array_keys($bind))); // // $this->_getWriteAdapter()->query($sql, $bind); // if (!$lastId = $this->_getWriteAdapter()->lastInsertId()) { // $select = $this->_getReadAdapter()->select() // ->from($attribute->getBackend()->getTable(), 'value_id') // ->where($entityIdField . '=?', $row[$entityIdField]) // ->where('entity_type_id=?', $row['entity_type_id']) // ->where('attribute_id=?', $row['attribute_id']) // ->where('store_id=?', $row['store_id']); // $lastId = $select->query()->fetchColumn(); // } // if ($object->getStoreId() != $this->getDefaultStoreId()) { // $this->_updateAttribute($object, $attribute, $lastId, $value); // } // return $this; }