Пример #1
0
 /**
  * Perform operations after object save
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Cms_Model_Resource_Block
  */
 protected function _afterSave(Mage_Core_Model_Abstract $object)
 {
     $oldStores = $this->lookupStoreIds($object->getId());
     $newStores = (array) $object->getStores();
     $table = $this->getTable('cms/block_store');
     $insert = array_diff($newStores, $oldStores);
     $delete = array_diff($oldStores, $newStores);
     if ($delete) {
         $where = array('block_id = ?' => (int) $object->getId(), 'store_id IN (?)' => $delete);
         $this->_getWriteAdapter()->delete($table, $where);
     }
     if ($insert) {
         $data = array();
         foreach ($insert as $storeId) {
             $data[] = array('block_id' => (int) $object->getId(), 'store_id' => (int) $storeId);
         }
         $this->_getWriteAdapter()->insertMultiple($table, $data);
     }
     return parent::_afterSave($object);
 }
 /**
  * Assign trigger to store views
  *
  * @param Mage_Core_Model_Abstract $object
  * @return self
  */
 protected function _afterSave(Mage_Core_Model_Abstract $object)
 {
     $oldStores = $this->lookupStoreIds($object->getId());
     $newStores = (array) $object->getStores();
     if (empty($newStores)) {
         $newStores = (array) $object->getStoreId();
     }
     $table = $this->getTable('esendex_sms/trigger_store');
     $insert = array_diff($newStores, $oldStores);
     $delete = array_diff($oldStores, $newStores);
     if (count($delete)) {
         $where = ['trigger_id = ?' => (int) $object->getId(), 'store_id IN (?)' => $delete];
         $this->_getWriteAdapter()->delete($table, $where);
     }
     if (count($insert)) {
         $data = [];
         foreach ($insert as $storeId) {
             $data[] = ['trigger_id' => (int) $object->getId(), 'store_id' => (int) $storeId];
         }
         $this->_getWriteAdapter()->insertMultiple($table, $data);
     }
     return parent::_afterSave($object);
 }
Пример #3
0
 /**
  * Perform actions after object save
  *
  * @param Varien_Object $object
  * @return Mage_Review_Model_Resource_Review
  */
 protected function _afterSave(Mage_Core_Model_Abstract $object)
 {
     $adapter = $this->_getWriteAdapter();
     /**
      * save detail
      */
     $detail = array('title' => $object->getTitle(), 'detail' => $object->getDetail(), 'nickname' => $object->getNickname());
     $select = $adapter->select()->from($this->_reviewDetailTable, 'detail_id')->where('review_id = :review_id');
     $detailId = $adapter->fetchOne($select, array(':review_id' => $object->getId()));
     if ($detailId) {
         $condition = array("detail_id = ?" => $detailId);
         $adapter->update($this->_reviewDetailTable, $detail, $condition);
     } else {
         $detail['store_id'] = $object->getStoreId();
         $detail['customer_id'] = $object->getCustomerId();
         $detail['review_id'] = $object->getId();
         $adapter->insert($this->_reviewDetailTable, $detail);
     }
     /**
      * save stores
      */
     $stores = $object->getStores();
     if (!empty($stores)) {
         $condition = array('review_id = ?' => $object->getId());
         $adapter->delete($this->_reviewStoreTable, $condition);
         $insertedStoreIds = array();
         foreach ($stores as $storeId) {
             if (in_array($storeId, $insertedStoreIds)) {
                 continue;
             }
             $insertedStoreIds[] = $storeId;
             $storeInsert = array('store_id' => $storeId, 'review_id' => $object->getId());
             $adapter->insert($this->_reviewStoreTable, $storeInsert);
         }
     }
     // reaggregate ratings, that depend on this review
     $this->_aggregateRatings($this->_loadVotedRatingIds($object->getId()), $object->getEntityPkValue());
     return $this;
 }
Пример #4
0
 /**
  * Assign page to store views
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Cms_Model_Resource_Page
  */
 protected function _afterSave(Mage_Core_Model_Abstract $object)
 {
     $oldStores = $this->lookupStoreIds($object->getId());
     $newStores = (array) $object->getStores();
     if (empty($newStores)) {
         $newStores = (array) $object->getStoreId();
     }
     $table = $this->getTable('cms/page_store');
     $insert = array_diff($newStores, $oldStores);
     $delete = array_diff($oldStores, $newStores);
     if ($delete) {
         $where = array('page_id = ?' => (int) $object->getId(), 'store_id IN (?)' => $delete);
         $this->_getWriteAdapter()->delete($table, $where);
     }
     if ($insert) {
         $data = array();
         foreach ($insert as $storeId) {
             $data[] = array('page_id' => (int) $object->getId(), 'store_id' => (int) $storeId);
         }
         $this->_getWriteAdapter()->insertMultiple($table, $data);
     }
     //Mark layout cache as invalidated
     Mage::app()->getCacheInstance()->invalidateType('layout');
     return parent::_afterSave($object);
 }
 /**
  * Add link stores for custom method
  *
  * @param Mage_Core_Model_Abstract $object
  *
  * @return MatheusGontijo_EasyShippingRules_Model_Resource_Custommethod
  */
 protected function _addLinkStores(Mage_Core_Model_Abstract $object)
 {
     $oldStores = $this->lookupStoreIds($object->getId());
     $newStores = (array) $object->getStores();
     if (empty($newStores)) {
         $newStores = (array) $object->getStoreId();
     }
     $table = $this->getTable('easyshippingrules/custom_method_store');
     $insert = array_diff($newStores, $oldStores);
     $delete = array_diff($oldStores, $newStores);
     if ($delete) {
         $where = array('easyshippingrules_custom_method_id = ?' => $object->getId(), 'store_id IN (?)' => $delete);
         $this->_getWriteAdapter()->delete($table, $where);
     }
     if ($insert) {
         $data = array();
         foreach ($insert as $storeId) {
             $data[] = array('easyshippingrules_custom_method_id' => $object->getId(), 'store_id' => $storeId);
         }
         $this->_getWriteAdapter()->insertMultiple($table, $data);
     }
     return $this;
 }
Пример #6
0
 /**
  * Function called after a model is saved
  * Save store associations
  *
  * @param Mage_Core_Model_Abstract $object
  * @return $this
  */
 protected function _afterSave(Mage_Core_Model_Abstract $object)
 {
     if ($object->getId()) {
         $oldStores = $this->lookupStoreIds($object->getId());
         $newStores = (array) $object->getStores();
         if (empty($newStores)) {
             $newStores = (array) $object->getStoreId();
         }
         $table = $this->getTable('splash/page_store');
         $insert = array_diff($newStores, $oldStores);
         $delete = array_diff($oldStores, $newStores);
         if ($delete) {
             $this->_getWriteAdapter()->delete($table, array('page_id = ?' => (int) $object->getId(), 'store_id IN (?)' => $delete));
         }
         if ($insert) {
             $data = array();
             foreach ($insert as $storeId) {
                 $data[] = array('page_id' => (int) $object->getId(), 'store_id' => (int) $storeId);
             }
             $this->_getWriteAdapter()->insertMultiple($table, $data);
         }
     }
     // Ensure that attribute's used are set to be used in the product listing
     if (is_array($optionFilters = $object->getOptionFilters())) {
         foreach ($optionFilters as $attribute => $data) {
             $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attribute);
             if ($attribute->getId() && !$attribute->getUsedInProductListing()) {
                 try {
                     $attribute->setUsedInProductListing(1)->save();
                 } catch (Exception $e) {
                     Mage::logException($e);
                 }
             }
         }
     }
     return parent::_afterSave($object);
 }
Пример #7
0
 /**
  * Assign image to store views
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Devils_HomeWidget_Model_Resource_Image
  */
 protected function _afterSave(Mage_Core_Model_Abstract $object)
 {
     $entityId = (int) $object->getId();
     $oldStores = $this->lookupStoreIds($entityId);
     $newStores = (array) $object->getStores();
     if (empty($newStores)) {
         $newStores = (array) $object->getStoreId();
     }
     $table = $this->getTable('devils_homewidget/image_store');
     $insertStores = array_diff($newStores, $oldStores);
     $deleteStores = array_diff($oldStores, $newStores);
     if ($deleteStores) {
         $where = array('entity_id = ?' => $entityId, 'store_id IN (?)' => $deleteStores);
         $this->_getWriteAdapter()->delete($table, $where);
     }
     if ($insertStores) {
         $data = array();
         foreach ($insertStores as $storeId) {
             $data[] = array('entity_id' => $entityId, 'store_id' => (int) $storeId);
         }
         $this->_getWriteAdapter()->insertMultiple($table, $data);
     }
     $areas = $object->getAreas();
     $table = $this->getTable('devils_homewidget/image_area');
     $where = array('entity_id = ?' => $entityId);
     $this->_getWriteAdapter()->delete($table, $where);
     foreach ($areas as &$area) {
         $area['entity_id'] = $entityId;
     }
     $this->_getWriteAdapter()->insertMultiple($table, $areas);
     //Mark layout cache as invalidated
     Mage::app()->getCacheInstance()->invalidateType('layout');
     return parent::_afterSave($object);
 }