/**
  * Delete entity
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Catalog_Model_Resource_Attribute
  */
 public function deleteEntity(Mage_Core_Model_Abstract $object)
 {
     if (!$object->getEntityAttributeId()) {
         return $this;
     }
     $select = $this->_getReadAdapter()->select()->from($this->getTable('eav/entity_attribute'))->where('entity_attribute_id = ?', (int) $object->getEntityAttributeId());
     $result = $this->_getReadAdapter()->fetchRow($select);
     if ($result) {
         $attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $result['attribute_id']);
         if (!$attribute->getData('is_user_defined')) {
             Mage::throwException(Mage::helper('eav')->__("Attribute '%s' is a system attribute and must be included in all attribute sets.", $attribute->getAttributeCode()));
         }
         if ($this->isUsedBySuperProducts($attribute, $result['attribute_set_id'])) {
             Mage::throwException(Mage::helper('eav')->__("Attribute '%s' used in configurable products and can not be removed from '%s' attribute set", $attribute->getAttributeCode(), $object->getAttributeSetName()));
         }
     }
     $condition = array('entity_attribute_id = ?' => $object->getEntityAttributeId());
     $this->_getWriteAdapter()->delete($this->getTable('entity_attribute'), $condition);
     return $this;
 }
Пример #2
0
 /**
  * Enter description here...
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Eav_Model_Mysql4_Entity_Attribute
  */
 public function deleteEntity(Mage_Core_Model_Abstract $object)
 {
     $write = $this->_getWriteAdapter();
     $condition = $write->quoteInto($this->getTable('entity_attribute') . '.entity_attribute_id = ?', $object->getEntityAttributeId());
     /**
      * Delete attribute values
      */
     $select = $write->select()->from($this->getTable('entity_attribute'))->where($condition);
     $data = $write->fetchRow($select);
     if (!empty($data)) {
         /**
          * @todo !!!! need fix retrieving attribute entity, this realization is temprary
          */
         $attribute = Mage::getModel('eav/entity_attribute')->load($data['attribute_id'])->setEntity(Mage::getSingleton('catalog/product')->getResource());
         if ($backendTable = $attribute->getBackend()->getTable()) {
             $clearCondition = array($write->quoteInto('entity_type_id=?', $attribute->getEntityTypeId()), $write->quoteInto('attribute_id=?', $attribute->getId()), $write->quoteInto('entity_id IN (
                     SELECT entity_id FROM ' . $attribute->getEntity()->getEntityTable() . ' WHERE attribute_set_id=?)', $data['attribute_set_id']));
             $write->delete($backendTable, $clearCondition);
         }
     }
     $write->delete($this->getTable('entity_attribute'), $condition);
     return $this;
 }
Пример #3
0
 /**
  * Delete entity
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Catalog_Model_Resource_Attribute
  */
 public function deleteEntity(Mage_Core_Model_Abstract $object)
 {
     if (!$object->getEntityAttributeId()) {
         return $this;
     }
     $select = $this->_getReadAdapter()->select()->from($this->getTable('eav/entity_attribute'))->where('entity_attribute_id = ?', (int) $object->getEntityAttributeId());
     $result = $this->_getReadAdapter()->fetchRow($select);
     if ($result) {
         $attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $result['attribute_id']);
         if ($this->isUsedBySuperProducts($attribute, $result['attribute_set_id'])) {
             Mage::throwException(Mage::helper('eav')->__("Attribute '%s' used in configurable products", $attribute->getAttributeCode()));
         }
         $backendTable = $attribute->getBackend()->getTable();
         if ($backendTable) {
             $select = $this->_getWriteAdapter()->select()->from($attribute->getEntity()->getEntityTable(), 'entity_id')->where('attribute_set_id = ?', $result['attribute_set_id']);
             $clearCondition = array('entity_type_id =?' => $attribute->getEntityTypeId(), 'attribute_id =?' => $attribute->getId(), 'entity_id IN (?)' => $select);
             $this->_getWriteAdapter()->delete($backendTable, $clearCondition);
         }
     }
     $condition = array('entity_attribute_id = ?' => $object->getEntityAttributeId());
     $this->_getWriteAdapter()->delete($this->getTable('entity_attribute'), $condition);
     return $this;
 }
Пример #4
0
 /**
  * Delete entity
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Eav_Model_Resource_Entity_Attribute
  */
 public function deleteEntity(Mage_Core_Model_Abstract $object)
 {
     if (!$object->getEntityAttributeId()) {
         return $this;
     }
     $this->_getWriteAdapter()->delete($this->getTable('eav_entity_attribute'), array('entity_attribute_id = ?' => $object->getEntityAttributeId()));
     return $this;
 }