Пример #1
0
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     $connection = $this->_getWriteAdapter();
     $select = $connection->select()->from($this->getMainTable(), 'key_id')->where('string=?', $object->getString())->where('store_id=?', 0);
     $object->setId($connection->fetchOne($select));
     return parent::_beforeSave($object);
 }
Пример #2
0
 /**
  * Validate unique configuration data before save
  * Set id to object if exists configuration instead of throw exception
  *
  * @param Mage_Core_Model_Config_Data $object
  * @return Mage_Core_Model_Resource_Config_Data
  */
 protected function _checkUnique(Mage_Core_Model_Abstract $object)
 {
     $select = $this->_getReadAdapter()->select()->from($this->getMainTable(), array($this->getIdFieldName()))->where('scope = :scope')->where('scope_id = :scope_id')->where('path = :path');
     $bind = array('scope' => $object->getScope(), 'scope_id' => $object->getScopeId(), 'path' => $object->getPath());
     $configId = $this->_getReadAdapter()->fetchOne($select, $bind);
     if ($configId) {
         $object->setId($configId);
     }
     return $this;
 }
Пример #3
0
 public function insertJoinedDatabase(Mage_Core_Model_Abstract $object)
 {
     $adapter = $this->_getWriteAdapter();
     $select = $adapter->select()->from($this->getMainTable(), array($this->getIdFieldName()))->where('program_id = ?', $object->getData('program_id'))->where('account_id = ?', $object->getData('account_id'));
     if ($adapter->fetchOne($select) === false) {
         $object->setId(null);
         $this->save($object);
     }
     return $this;
 }
Пример #4
0
 /**
  * Clean cache by specified product and its ids
  *
  * @param Mage_Core_Model_Abstract $entity
  * @param array $ids
  */
 protected function _cleanProductsCache(Mage_Core_Model_Abstract $entity, array $ids)
 {
     $cacheTags = array();
     foreach ($ids as $entityId) {
         $entity->setId($entityId);
         $cacheTags = array_unique(array_merge($cacheTags, $entity->getCacheIdTagsWithCategories()));
     }
     if (!empty($cacheTags)) {
         Enterprise_PageCache_Model_Cache::getCacheInstance()->clean($cacheTags);
     }
 }
Пример #5
0
 /**
  * Clean cache by specified entity and its ids
  *
  * @param Mage_Core_Model_Abstract $entity
  * @param array $ids
  */
 protected function _cleanEntityCache(Mage_Core_Model_Abstract $entity, array $ids)
 {
     $cacheTags = array();
     foreach ($ids as $entityId) {
         $entity->setId($entityId);
         $cacheTags = array_merge($cacheTags, $entity->getCacheIdTags());
     }
     if (!empty($cacheTags)) {
         Ves_Optimize_Model_Cache::getCacheInstance()->clean($cacheTags);
     }
 }
Пример #6
0
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if (!$object->getId() && $object->getStatus() == $object->getApprovedStatus()) {
         $searchTag = new Varien_Object();
         $this->loadByName($searchTag, $object->getName());
         if ($searchTag->getData($this->getIdFieldName()) && $searchTag->getStatus() == $object->getPendingStatus()) {
             $object->setId($searchTag->getData($this->getIdFieldName()));
         }
     }
     if (Mage::helper('core/string')->strlen($object->getName()) > 255) {
         $object->setName(Mage::helper('core/string')->substr($object->getName(), 0, 255));
     }
     return parent::_beforeSave($object);
 }
Пример #7
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());
     }
 }
Пример #8
0
 /**
  * Before save
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Core_Model_Resource_Translate_String
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     $adapter = $this->_getWriteAdapter();
     $select = $adapter->select()->from($this->getMainTable(), 'key_id')->where('string = :string')->where('store_id = :store_id');
     $bind = array('string' => $object->getString(), 'store_id' => Mage_Core_Model_App::ADMIN_STORE_ID);
     $object->setId($adapter->fetchOne($select, $bind));
     return parent::_beforeSave($object);
 }
Пример #9
0
 /**
  * clearEntityCache
  *
  * @param Mage_Core_Model_Abstract $entity
  * @param array $ids
  * @return void
  */
 public function clearEntityCache(Mage_Core_Model_Abstract $entity, array $ids)
 {
     $cacheTags = array();
     foreach ($ids as $entityId) {
         $entity->setId($entityId);
         $cacheTags = array_merge($cacheTags, $entity->getCacheIdTags());
     }
     if (!empty($cacheTags)) {
         Enterprise_PageCache_Model_Cache::getCacheInstance()->clean($cacheTags);
     }
 }
Пример #10
0
 /**
  * Callback for delete method in mocked model
  */
 public function deleteModelSuccessfully()
 {
     $this->_model->setId(null);
 }