Пример #1
0
 /**
  * Clear useless attribute values
  *
  * @param  Mage_Core_Model_Abstract $object
  * @return Mage_Catalog_Model_Resource_Attribute
  */
 protected function _clearUselessAttributeValues(Mage_Core_Model_Abstract $object)
 {
     $origData = $object->getOrigData();
     if ($object->isScopeGlobal() && isset($origData['is_global']) && Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL != $origData['is_global']) {
         $attributeStoreIds = array_keys(Mage::app()->getStores());
         if (!empty($attributeStoreIds)) {
             $delCondition = array('entity_type_id=?' => $object->getEntityTypeId(), 'attribute_id = ?' => $object->getId(), 'store_id IN(?)' => $attributeStoreIds);
             $this->_getWriteAdapter()->delete($object->getBackendTable(), $delCondition);
         }
     }
     return $this;
 }
Пример #2
0
 public function save(Mage_Core_Model_Abstract $object)
 {
     $write = $this->_getWriteAdapter();
     $setId = $object->getId();
     $data = array('attribute_set_name' => $object->getAttributeSetName());
     $write->beginTransaction();
     try {
         if (intval($setId) > 0) {
             $condition = $write->quoteInto("{$this->getMainTable()}.{$this->getIdFieldName()} = ?", $setId);
             $write->update($this->getMainTable(), $data, $condition);
             if ($object->getGroups()) {
                 foreach ($object->getGroups() as $group) {
                     $group->save();
                 }
             }
             if ($object->getRemoveGroups()) {
                 foreach ($object->getRemoveGroups() as $group) {
                     $group->delete($group->getId());
                 }
             }
             if ($object->getRemoveAttributes()) {
                 foreach ($object->getRemoveAttributes() as $attribute) {
                     $attribute->deleteEntity();
                 }
             }
         } else {
             $data['entity_type_id'] = $object->getEntityTypeId();
             $write->insert($this->getMainTable(), $data);
             $object->setId($write->lastInsertId());
         }
         $write->commit();
     } catch (Exception $e) {
         $write->rollback();
         throw new Exception($e->getMessage());
     }
 }
Пример #3
0
 /**
  * Save entity attribute value
  *
  * Collect for mass save
  *
  * @param Mage_Core_Model_Abstract $object
  * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
  * @param mixed $value
  * @return Mage_Eav_Model_Entity_Abstract
  */
 protected function _saveAttribute($object, $attribute, $value)
 {
     $table = $attribute->getBackend()->getTable();
     if (!isset($this->_attributeValuesToSave[$table])) {
         $this->_attributeValuesToSave[$table] = array();
     }
     $entityIdField = $attribute->getBackend()->getEntityIdField();
     $data = array('entity_type_id' => $object->getEntityTypeId(), $entityIdField => $object->getId(), 'attribute_id' => $attribute->getId(), 'value' => $this->_prepareValueForSave($value, $attribute));
     $this->_attributeValuesToSave[$table][] = $data;
     return $this;
 }
Пример #4
0
 /**
  * Set entity instance
  *
  * @param Mage_Core_Model_Abstract $entity
  * @return Mage_Eav_Model_Form
  */
 public function setEntity(Mage_Core_Model_Abstract $entity)
 {
     $this->_entity = $entity;
     if ($entity->getEntityTypeId()) {
         $this->setEntityType($entity->getEntityTypeId());
     }
     return $this;
 }
Пример #5
0
 /**
  * Load additional attribute data.
  * Load label of current active store
  *
  * @param Mage_Eav_Model_Entity_Attribute|Mage_Core_Model_Abstract $object
  * @return Mage_Eav_Model_Resource_Entity_Attribute
  */
 protected function _afterLoad(Mage_Core_Model_Abstract $object)
 {
     /** @var $entityType Mage_Eav_Model_Entity_Type */
     $entityType = $object->getData('entity_type');
     if ($entityType) {
         $additionalTable = $entityType->getAdditionalAttributeTable();
     } else {
         $additionalTable = $this->getAdditionalAttributeTable($object->getEntityTypeId());
     }
     if ($additionalTable) {
         $adapter = $this->_getReadAdapter();
         $bind = array(':attribute_id' => $object->getId());
         $select = $adapter->select()->from($this->getTable($additionalTable))->where('attribute_id = :attribute_id');
         $result = $adapter->fetchRow($select, $bind);
         if ($result) {
             $object->addData($result);
         }
     }
     return $this;
 }
Пример #6
0
 /**
  * Load additional attribute data.
  * Load label of current active store
  *
  * @param Varien_Object $object
  * @return Mage_Eav_Model_Mysql4_Entity_Attribute
  */
 protected function _afterLoad(Mage_Core_Model_Abstract $object)
 {
     if ($entityType = $object->getData('entity_type')) {
         $additionalTable = $entityType->getAdditionalAttributeTable();
     } else {
         $additionalTable = $this->getAdditionalAttributeTable($object->getEntityTypeId());
     }
     if ($additionalTable) {
         $select = $this->_getReadAdapter()->select()->from($this->getTable($additionalTable))->where('attribute_id = ?', $object->getId());
         if ($result = $this->_getReadAdapter()->fetchRow($select)) {
             $object->addData($result);
         }
     }
     return $this;
 }
 /**
  * Enter description here...
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Eav_Model_Mysql4_Entity_Attribute
  */
 public function saveInSetIncluding(Mage_Core_Model_Abstract $object)
 {
     $attrId = $object->getId();
     $setId = (int) $object->getAttributeSetId();
     $groupId = (int) $object->getAttributeGroupId();
     if ($setId && $groupId && $object->getEntityTypeId()) {
         $write = $this->_getWriteAdapter();
         $table = $this->getTable('entity_attribute');
         $data = array('entity_type_id' => $object->getEntityTypeId(), 'attribute_set_id' => $setId, 'attribute_group_id' => $groupId, 'attribute_id' => $attrId, 'sort_order' => $object->getSortOrder() ? $object->getSortOrder() : $this->_getMaxSortOrder($object) + 1);
         $condition = "{$table}.attribute_id = '{$attrId}'\n                AND {$table}.attribute_set_id = '{$setId}'";
         $write->delete($table, $condition);
         $write->insert($table, $data);
     }
     return $this;
 }