/** * Delete entity * * @param \Magento\Framework\Model\AbstractModel $object * @return $this * @throws \Magento\Framework\Model\Exception */ public function deleteEntity(\Magento\Framework\Model\AbstractModel $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 = $this->_eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $result['attribute_id']); try { $this->attrLockValidator->validate($attribute, $result['attribute_set_id']); } catch (\Magento\Framework\Model\Exception $exception) { throw new \Magento\Framework\Model\Exception(__("Attribute '%1' is locked. ", $attribute->getAttributeCode()) . $exception->getMessage()); } $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('eav_entity_attribute'), $condition); return $this; }
/** * Delete entity * * @param \Magento\Framework\Model\AbstractModel $object * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function deleteEntity(\Magento\Framework\Model\AbstractModel $object) { if (!$object->getEntityAttributeId()) { return $this; } $result = $this->getEntityAttribute($object->getEntityAttributeId()); if ($result) { $attribute = $this->_eavConfig->getAttribute($object->getEntityTypeId(), $result['attribute_id']); try { $this->attrLockValidator->validate($attribute, $result['attribute_set_id']); } catch (\Magento\Framework\Exception\LocalizedException $exception) { throw new \Magento\Framework\Exception\LocalizedException(__('Attribute \'%1\' is locked. %2', $attribute->getAttributeCode(), $exception->getMessage())); } $backendTable = $attribute->getBackend()->getTable(); if ($backendTable) { $linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField(); $select = $this->getConnection()->select()->from($attribute->getEntity()->getEntityTable(), $linkField)->where('attribute_set_id = ?', $result['attribute_set_id']); $clearCondition = ['attribute_id =?' => $attribute->getId(), $linkField . ' IN (?)' => $select]; $this->getConnection()->delete($backendTable, $clearCondition); } } $condition = ['entity_attribute_id = ?' => $object->getEntityAttributeId()]; $this->getConnection()->delete($this->getTable('eav_entity_attribute'), $condition); return $this; }
/** * Processing object before save data * * @return \Magento\Framework\Model\AbstractModel * @throws \Magento\Eav\Exception */ protected function _beforeSave() { try { $this->attrLockValidator->validate($this); } catch (\Magento\Framework\Model\Exception $exception) { throw new \Magento\Eav\Exception($exception->getMessage()); } $this->setData('modulePrefix', self::MODULE_NAME); return parent::_beforeSave(); }
/** * Processing object before save data * * @return \Magento\Framework\Model\AbstractModel * @throws \Magento\Eav\Exception */ public function beforeSave() { try { $this->attrLockValidator->validate($this); } catch (\Magento\Framework\Exception\LocalizedException $exception) { throw new \Magento\Eav\Exception(__($exception->getMessage())); } $this->setData('modulePrefix', self::MODULE_NAME); return parent::beforeSave(); }
/** * Register indexing event before delete catalog eav attribute * * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function beforeDelete() { $this->attrLockValidator->validate($this); return parent::beforeDelete(); }
/** * Register indexing event before delete catalog eav attribute * * @return $this * @throws \Magento\Framework\Model\Exception */ protected function _beforeDelete() { $this->attrLockValidator->validate($this); return parent::_beforeDelete(); }