/** * Action before save * * @param Mage_Core_Model_Abstract $object * @return Mage_Api_Model_Resource_Acl_Role */ protected function _beforeSave(Mage_Core_Model_Abstract $object) { if (!$object->getId()) { $this->setCreated(Mage::getSingleton('core/date')->gmtDate()); } return $this; }
/** * Process page data before saving * * @param Mage_Core_Model_Abstract $object */ protected function _afterSave(Mage_Core_Model_Abstract $object) { $condition = $this->_getWriteAdapter()->quoteInto('productattachments_id = ?', $object->getId()); $r = $this->_getReadAdapter()->select('p.block_name_product')->from(array('p' => $this->getTable('productattachments_store')))->where('productattachments_id = (?)', $object->getId())->limit(1); $row = $this->_getReadAdapter()->fetchRow($r); $block_name = ''; if (isset($row['block_name_product'])) { $block_name = $row['block_name_product']; } $this->_getWriteAdapter()->delete($this->getTable('productattachments_store'), $condition); foreach ((array) $object->getData('stores') as $store) { $storeArray = array(); $storeArray['productattachments_id'] = $object->getId(); $storeArray['store_id'] = $store; $this->_getWriteAdapter()->insert($this->getTable('productattachments_store'), $storeArray); } //Get Related Products $links = $object['links']; if (isset($links['related'])) { $productIds = Mage::helper('adminhtml/js')->decodeGridSerializedInput($links['related']); $this->_getWriteAdapter()->delete($this->getTable('productattachments_products'), $condition); //Save Related Products foreach ($productIds as $_product) { $newsArray = array(); $newsArray['productattachments_id'] = $object->getId(); $newsArray['product_id'] = $_product; $newsArray['block_name_product'] = $block_name; $this->_getWriteAdapter()->insert($this->getTable('productattachments_products'), $newsArray); } } return parent::_afterSave($object); }
protected function _afterSave(Mage_Core_Model_Abstract $object) { $read = $this->_getReadAdapter(); $write = $this->_getWriteAdapter(); if ($object->getType() == BL_CustomGrid_Model_Options_Source::SOURCE_TYPE_MAGE_MODEL) { // Save corresponding model $table = $this->getTable('customgrid/options_source_model'); // Delete source model(s) $delete = array($write->quoteInto('source_id = ?', $object->getId())); if ($object->getModelId()) { // But keep updated model if set $delete[] = $write->quoteInto('model_id != ?', $object->getModelId()); } $write->delete($table, $delete); // Insert or update model $values = array('source_id' => $object->getId(), 'model_name' => $object->getModelName(), 'model_type' => $object->getModelType(), 'method' => $object->getMethod(), 'return_type' => $object->getReturnType(), 'value_key' => $object->getValueKey(), 'label_key' => $object->getLabelKey()); $updated = false; if ($object->getModelId()) { $query = $read->select()->from($table)->where('source_id = ' . $object->getId() . ' AND model_id = ?', $object->getModelId()); if ($read->fetchOne($query)) { // Update model if given ID correspond to a model that actually belong to saved source $write->update($table, $values, $write->quoteInto('model_id = ?', $object->getModelId())); $updated = true; } } if (!$updated) { // Else (no ID or not found for source), insert it $write->insert($table, $values); } } else { // Save corresponding options $table = $this->getTable('customgrid/options_source_option'); $options = $object->getOptions(); if (is_array($options)) { // Get existing options IDs $select = $read->select()->from($table, 'option_id')->where('source_id = ?', $object->getId()); $existingIds = $read->fetchCol($select); $foundIds = array(); foreach ($options as $option) { $values = array('source_id' => $object->getId(), 'value' => $option['value'], 'label' => $option['label']); if ($option['option_id'] > 0 && in_array($option['option_id'], $existingIds) && (!isset($option['delete']) || !$option['delete'])) { // Existing option to update $write->update($table, $values, $write->quoteInto('option_id = ?', $option['option_id'])); $foundIds[] = $option['option_id']; } elseif (!isset($option['delete']) || !$option['delete']) { // New (or not found for saved source) option to insert $write->insert($table, $values); } } // Remove missing / deleted options $delete = array_diff($existingIds, $foundIds); if (!empty($delete)) { foreach ($delete as $optionId) { $write->delete($table, $write->quoteInto('option_id = ?', $optionId)); } } } } return parent::_afterSave($object); }
/** * * @param Mage_Core_Model_Abstract $object */ protected function _afterLoad(Mage_Core_Model_Abstract $object) { if ($object->getId()) { // Stores $select = $this->_getReadAdapter()->select()->from($this->getTable('auguria_sliders/stores'))->where('slider_id = ?', $object->getId()); if ($data = $this->_getReadAdapter()->fetchAll($select)) { $storesArray = array(); foreach ($data as $row) { $storesArray[] = $row['store_id']; } $object->setData('stores', $storesArray); } // Cms pages $select = $this->_getReadAdapter()->select()->from($this->getTable('auguria_sliders/pages'))->where('slider_id = ?', $object->getId()); if ($data = $this->_getReadAdapter()->fetchAll($select)) { $pagesArray = array(); foreach ($data as $row) { $pagesArray[] = $row['page_id']; } $object->setData('pages', $pagesArray); } // Category ids $select = $this->_getReadAdapter()->select()->from($this->getTable('auguria_sliders/categories'))->where('slider_id = ?', $object->getId()); if ($data = $this->_getReadAdapter()->fetchAll($select)) { $categoriesArray = array(); foreach ($data as $row) { $categoriesArray[] = $row['category_id']; } $object->setData('category_ids', $categoriesArray); } } return parent::_afterLoad($object); }
/** * Reset current store to admin and clean up created customer entity */ protected function tearDown() { $this->setCurrentStore('admin'); if ($this->_model && $this->_model->getId()) { $this->_model->delete(); } }
/** * Perform actions after object save * * @param Mage_Core_Model_Abstract $object * @return Mage_Eav_Model_Resource_Entity_Attribute_Set */ protected function _afterSave(Mage_Core_Model_Abstract $object) { if ($object->getGroups()) { /* @var $group Mage_Eav_Model_Entity_Attribute_Group */ foreach ($object->getGroups() as $group) { $group->setAttributeSetId($object->getId()); if ($group->itemExists() && !$group->getId()) { continue; } $group->save(); } } if ($object->getRemoveGroups()) { foreach ($object->getRemoveGroups() as $group) { /* @var $group Mage_Eav_Model_Entity_Attribute_Group */ $group->delete(); } Mage::getResourceModel('eav/entity_attribute_group')->updateDefaultGroup($object->getId()); } if ($object->getRemoveAttributes()) { foreach ($object->getRemoveAttributes() as $attribute) { /* @var $attribute Mage_Eav_Model_Entity_Attribute */ $attribute->deleteEntity(); } } return parent::_afterSave($object); }
/** * Set personalisation tags on the object. * * @param Mage_Core_Model_Abstract $object * @return Mage_Cms_Model_Resource_Block */ protected function _afterLoad(Mage_Core_Model_Abstract $object) { if ($object->getId()) { $object->setData('personalisation_tags', $this->lookupPersonalisationTags($object->getId())); } return parent::_afterLoad($object); }
/** * Bind gift rule to customer group(s) and website(s). * Save rule's associated store labels. * Save product attributes used in rule. * * @param Mage_Core_Model_Abstract $object * * @return Mage_SalesRule_Model_Resource_Rule */ protected function _afterSave(Mage_Core_Model_Abstract $object) { if ($object->hasStoreLabels()) { $this->saveStoreLabels($object->getId(), $object->getStoreLabels()); } if ($object->hasWebsiteIds()) { $websiteIds = $object->getWebsiteIds(); if (!is_array($websiteIds)) { $websiteIds = explode(',', (string) $websiteIds); } $this->bindRuleToEntity($object->getId(), $websiteIds, 'website'); } if ($object->hasCustomerGroupIds()) { $customerGroupIds = $object->getCustomerGroupIds(); if (!is_array($customerGroupIds)) { $customerGroupIds = explode(',', (string) $customerGroupIds); } $this->bindRuleToEntity($object->getId(), $customerGroupIds, 'customer_group'); } if ($object->hasProductIds()) { $productIds = $object->getProductIds(); if (!is_array($productIds)) { $productIds = explode(',', (string) $productIds); } $this->bindRuleToEntity($object->getId(), $productIds, 'product'); } // Save product attributes used in rule $ruleProductAttributes = array_merge($this->getProductAttributes(serialize($object->getConditions()->asArray())), $this->getProductAttributes(serialize($object->getActions()->asArray()))); if (count($ruleProductAttributes)) { $this->setActualProductAttributes($object, $ruleProductAttributes); } return parent::_afterSave($object); }
/** * Save attribute options * Override to save image to attribute option * * @param Mage_Core_Model_Abstract $object * @return Mage_Eav_Model_Resource_Entity_Attribute * @version 1.7.0.2 */ protected function _saveOption(Mage_Core_Model_Abstract $object) { $option = $object->getOption(); if (is_array($option)) { $adapter = $this->_getWriteAdapter(); $optionTable = $this->getTable('eav/attribute_option'); $optionValueTable = $this->getTable('eav/attribute_option_value'); $stores = Mage::app()->getStores(true); if (isset($option['value'])) { $attributeDefaultValue = array(); if (!is_array($object->getDefault())) { $object->setDefault(array()); } foreach ($option['value'] as $optionId => $values) { $intOptionId = (int) $optionId; if (!empty($option['delete'][$optionId])) { if ($intOptionId) { $adapter->delete($optionTable, array('option_id = ?' => $intOptionId)); } continue; } $sortOrder = !empty($option['order'][$optionId]) ? $option['order'][$optionId] : 0; $image = !empty($option['image'][$optionId]) ? $option['image'][$optionId] : null; $thumb = !empty($option['thumb'][$optionId]) ? $option['thumb'][$optionId] : null; if (!$intOptionId) { $data = array('attribute_id' => $object->getId(), 'sort_order' => $sortOrder, 'image' => $image, 'thumb' => $thumb); $adapter->insert($optionTable, $data); $intOptionId = $adapter->lastInsertId($optionTable); } else { $data = array('sort_order' => $sortOrder, 'image' => $image, 'thumb' => $thumb); $where = array('option_id =?' => $intOptionId); $adapter->update($optionTable, $data, $where); } if (in_array($optionId, $object->getDefault())) { if ($object->getFrontendInput() == 'multiselect') { $attributeDefaultValue[] = $intOptionId; } elseif ($object->getFrontendInput() == 'select') { $attributeDefaultValue = array($intOptionId); } } // Default value if (!isset($values[0])) { Mage::throwException(Mage::helper('eav')->__('Default option value is not defined')); } $adapter->delete($optionValueTable, array('option_id =?' => $intOptionId)); foreach ($stores as $store) { if (isset($values[$store->getId()]) && (!empty($values[$store->getId()]) || $values[$store->getId()] == "0")) { $data = array('option_id' => $intOptionId, 'store_id' => $store->getId(), 'value' => $values[$store->getId()]); $adapter->insert($optionValueTable, $data); } } } $bind = array('default_value' => implode(',', $attributeDefaultValue)); $where = array('attribute_id =?' => $object->getId()); $adapter->update($this->getMainTable(), $bind, $where); } } return $this; }
/** * Callback for save method in mocked model * * @throws Magento_Exception */ public function saveModelAndFailOnUpdate() { if (!$this->_model->getId()) { $this->saveModelSuccessfully(); } else { throw new Magento_Exception('Synthetic model update failure.'); } }
protected function _afterDelete(Mage_Core_Model_Abstract $object) { //delete values $this->_getReadAdapter()->delete($this->getTable('webforms/results_values'), 'field_id =' . $object->getId()); $this->_getReadAdapter()->delete($this->getTable('webforms/logic'), 'field_id =' . $object->getId()); Mage::dispatchEvent('webforms_field_delete', array('field' => $object)); return parent::_afterDelete($object); }
/** * Perform operations after object load * * @param Mage_Core_Model_Abstract $object * @return Mage_Cms_Model_Resource_Page */ protected function _afterLoad(Mage_Core_Model_Abstract $object) { if ($object->getId()) { $products = $this->getProductIds($object->getId()); $object->setData('product_id', $products); } return parent::_afterLoad($object); }
protected function _afterLoad(Mage_Core_Model_Abstract $object) { if ($object->getId()) { $stores = $this->listStoreIds($object->getId()); $object->setData('store_id', $stores); } return parent::_afterLoad($object); }
protected function _afterDelete(Mage_Core_Model_Abstract $object) { //delete values $values = $this->_getReadAdapter()->delete($this->getTable('webforms/results_values'), 'result_id = ' . $object->getId()); $dir = Mage::getBaseDir('media') . DS . 'webforms' . DS . $object->getId(); $this->rrmdir($dir); Mage::dispatchEvent('webforms_result_delete', array('result' => $object)); return parent::_afterDelete($object); }
/** * Processing object after save data * Update app_code as Store + Device + 123 (increment). * * @param Mage_Core_Model_Abstract $object * @return Mage_Core_Model_Abstract */ protected function _afterSave(Mage_Core_Model_Abstract $object) { $appCode = $object->getCode(); $isCodePrefixed = $object->isCodePrefixed(); if (!$isCodePrefixed) { $this->_getWriteAdapter()->update($this->getMainTable(), array('code' => $appCode . $object->getId()), $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . '=?', $object->getId())); } return parent::_afterSave($object); }
protected function _saveOption(Mage_Core_Model_Abstract $object) { $option = $object->getOption(); if (is_array($option)) { $write = $this->_getWriteAdapter(); $optionTable = $this->getTable('attribute_option'); $optionValueTable = $this->getTable('attribute_option_value'); $stores = Mage::getModel('core/store')->getResourceCollection()->setLoadDefault(true)->load(); if (isset($option['value'])) { $attributeDefaultValue = array(); if (!is_array($object->getDefault())) { $object->setDefault(array()); } foreach ($option['value'] as $optionId => $values) { $intOptionId = (int) $optionId; if (!empty($option['delete'][$optionId])) { if ($intOptionId) { $condition = $write->quoteInto('option_id=?', $intOptionId); $write->delete($optionTable, $condition); } continue; } if (!$intOptionId) { $data = array('attribute_id' => $object->getId(), 'sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0, 'image' => isset($option['image'][$optionId]) ? $option['image'][$optionId] : '', 'thumb' => isset($option['thumb'][$optionId]) ? $option['thumb'][$optionId] : ''); $write->insert($optionTable, $data); $intOptionId = $write->lastInsertId(); } else { $data = array('sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0, 'image' => isset($option['image'][$optionId]) ? $option['image'][$optionId] : '', 'thumb' => isset($option['thumb'][$optionId]) ? $option['thumb'][$optionId] : ''); $write->update($optionTable, $data, $write->quoteInto('option_id=?', $intOptionId)); } if (in_array($optionId, $object->getDefault())) { if ($object->getFrontendInput() == 'multiselect') { $attributeDefaultValue[] = $intOptionId; } else { if ($object->getFrontendInput() == 'select') { $attributeDefaultValue = array($intOptionId); } } } // Default value if (!isset($values[0])) { Mage::throwException(Mage::helper('eav')->__('Default option value is not defined.')); } $write->delete($optionValueTable, $write->quoteInto('option_id=?', $intOptionId)); foreach ($stores as $store) { if (isset($values[$store->getId()]) && (!empty($values[$store->getId()]) || $values[$store->getId()] == "0")) { $data = array('option_id' => $intOptionId, 'store_id' => $store->getId(), 'value' => $values[$store->getId()]); $write->insert($optionValueTable, $data); } } } $write->update($this->getMainTable(), array('default_value' => implode(',', $attributeDefaultValue)), $write->quoteInto($this->getIdFieldName() . '=?', $object->getId())); } } return $this; }
protected function _afterLoad(Mage_Core_Model_Abstract $object) { if ($object->getId()) { $stores = $this->lookupStoreIds($object->getId()); $object->setData('store_id', $stores); $object->setData('stores', $stores); $object->setData('content_decode', unserialize($object->getContent())); } return parent::_afterLoad($object); }
/** * @param Mage_Core_Model_Abstract $object * @param array $labelValues * * @return $this */ public function setLabelValues(Mage_Core_Model_Abstract $object, $labelValues) { $write = $this->_getWriteAdapter(); $where = $write->quoteInto('status_id =?', $object->getId()); $write->delete($this->getTable('aw_hdu3/ticket_status_label'), $where); foreach ($labelValues as $storeId => $label) { $write->insert($this->getTable('aw_hdu3/ticket_status_label'), array('status_id' => $object->getId(), 'value' => $label, 'store_id' => $storeId)); } return $this; }
public function delete(Mage_Core_Model_Abstract $object) { $groups = $object->getGroupsArray(); $setId = $object->getSetId(); $write = $this->_getWriteAdapter(); $condition = $write->quoteInto("{$this->getTable('entity_attribute')}.attribute_group_id = ?", $object->getId()); $write->delete($this->getTable('entity_attribute'), $condition); $condition = $write->quoteInto('attribute_group_id = ?', $object->getId()); $write->delete($this->getMainTable(), $condition); }
protected function _afterLoad(Mage_Core_Model_Abstract $object) { if ($object->getId()) { if ($urlKey = Mage::getResourceModel('collpur/rewrite')->loadByDealId($object->getId(), 0)) { $object->setUrlKey($urlKey); } else { $object->setUrlKey(''); } } }
public function getIsUniqueBlockToStores(Mage_Core_Model_Abstract $object) { $select = $this->_getReadAdapter()->select()->from(array('cb' => $this->getMainTable()))->where('cb.identifier = ?', $object->getData('identifier')); if ($object->getId()) { $select->where('cb.id <> ?', $object->getId()); } if ($this->_getReadAdapter()->fetchRow($select)) { return false; } return true; }
protected function _beforeDelete(Mage_Core_Model_Abstract $object) { // Cleanup stats on mdlblog delete $adapter = $this->_getReadAdapter(); // 1. Delete mdlblog/store $adapter->delete($this->getTable('mdlblog/store'), 'post_id=' . $object->getId()); // 2. Delete mdlblog/post_cat $adapter->delete($this->getTable('mdlblog/post_cat'), 'post_id=' . $object->getId()); // 3. Delete mdlblog/post_comment $adapter->delete($this->getTable('mdlblog/comment'), 'post_id=' . $object->getId()); }
/** * Process page data before saving * * @param Mage_Core_Model_Abstract $object */ protected function _afterSave(Mage_Core_Model_Abstract $object) { $condition = $this->_getWriteAdapter()->quoteInto('banners_id = ?', $object->getId()); $this->_getWriteAdapter()->delete($this->getTable('banners_store'), $condition); foreach ((array) $object->getData('stores') as $store) { $storeArray = array(); $storeArray['banners_id'] = $object->getId(); $storeArray['store_id'] = $store; $this->_getWriteAdapter()->insert($this->getTable('banners_store'), $storeArray); } return parent::_afterSave($object); }
protected function _afterDelete(Mage_Core_Model_Abstract $object){ //delete fields $fields = Mage::getModel('webforms/fields')->getCollection()->addFilter('webform_id',$object->getId()); foreach($fields as $field){ $field->delete(); } //delete fieldsets $fieldsets = Mage::getModel('webforms/fieldsets')->getCollection()->addFilter('webform_id',$object->getId()); foreach($fieldsets as $fieldset){ $fieldset->delete(); } return parent::_afterDelete($object); }
public function isUniqueCategory(Mage_Core_Model_Abstract $object) { $title = trim($object->getTitle()); if (!empty($title)) { $select = $this->_getReadAdapter()->select()->from($this->getMainTable(), $this->getIdFieldName())->where('title = ?', $title); if ($object->getId()) { $select->where($this->getIdFieldName() . ' <> ?', $object->getId()); } if ($this->_getReadAdapter()->fetchRow($select)) { return false; } } return true; }
protected function _afterDelete(Mage_Core_Model_Abstract $object) { //delete values $this->_getReadAdapter()->delete($this->getTable('webforms/results_values'), 'result_id = ' . $object->getId()); $dir = Mage::getBaseDir('media') . DS . 'webforms' . DS . $object->getId(); $this->rrmdir($dir); //clear messages $messages = Mage::getModel('webforms/message')->getCollection()->addFilter('result_id', $object->getId()); foreach ($messages as $message) { $message->delete(); } Mage::dispatchEvent('webforms_result_delete', array('result' => $object)); return parent::_afterDelete($object); }
public function _afterSave(Mage_Core_Model_Abstract $object) { /** stores */ $deleteWhere = $this->_getWriteAdapter()->quoteInto('poll_id = ?', $object->getId()); $this->_getWriteAdapter()->delete($this->getTable('poll/poll_store'), $deleteWhere); foreach ($object->getStoreIds() as $storeId) { $pollStoreData = array('poll_id' => $object->getId(), 'store_id' => $storeId); $this->_getWriteAdapter()->insert($this->getTable('poll/poll_store'), $pollStoreData); } /** answers */ foreach ($object->getAnswers() as $answer) { $answer->setPollId($object->getId()); $answer->save(); } }
/** * @param Mage_Core_Model_Abstract $item * @return string */ public function getRowUrl($item) { switch ($item->getData('type')) { default: $url = false; break; case Open_Gallery_Model_Item::TYPE_VIDEO: $url = $this->getUrl('*/gallery_item_video/edit', array('_current' => true, 'id' => $item->getId(), 'category' => $this->getRequest()->getParam('id'))); break; case Open_Gallery_Model_Item::TYPE_IMAGE: $url = $this->getUrl('*/gallery_item_image/edit', array('_current' => true, 'id' => $item->getId(), 'category' => $this->getRequest()->getParam('id'))); break; } return $url; }
/** * Perform actions before object save * * @param Mage_Core_Model_Abstract $object * @return Mage_Core_Model_Resource_Db_Abstract * @throws Mage_Core_Exception */ public function _beforeSave(Mage_Core_Model_Abstract $object) { if ($date = $object->getDateFrom()) { $object->setDateFrom($this->formatDate($date)); } else { $object->setDateFrom(null); } if ($date = $object->getDateTo()) { $object->setDateTo($this->formatDate($date)); } else { $object->setDateTo(null); } if (!is_null($object->getDateFrom()) && !is_null($object->getDateTo()) && Varien_Date::toTimestamp($object->getDateFrom()) > Varien_Date::toTimestamp($object->getDateTo())) { Mage::throwException(Mage::helper('core')->__('Start date cannot be greater than end date.')); } $check = $this->_checkIntersection($object->getStoreId(), $object->getDateFrom(), $object->getDateTo(), $object->getId()); if ($check) { Mage::throwException(Mage::helper('core')->__('Your design change for the specified store intersects with another one, please specify another date range.')); } if ($object->getDateFrom() === null) { $object->setDateFrom(new Zend_Db_Expr('null')); } if ($object->getDateTo() === null) { $object->setDateTo(new Zend_Db_Expr('null')); } parent::_beforeSave($object); }
protected function _checkUniqueFields(Mage_Core_Model_Abstract $objectToSave) { $collection = $objectToSave->getCollection()->addFieldToFilter('direction', $objectToSave->getDirection()); foreach ($collection as $item) { if ($item->getId() == $objectToSave->getId()) { continue; } $this->_afterLoad($item); $customerGroupUniqueFlag = true; foreach ($objectToSave->getData('customer_group_ids') as $objectToSaveCustomerGroupId) { if (in_array($objectToSaveCustomerGroupId, $item->getData('customer_group_ids'))) { $customerGroupUniqueFlag = false; break; } } $websiteUniqueFlag = true; foreach ($objectToSave->getData('website_ids') as $objectToSaveWebsiteId) { if (in_array($objectToSaveWebsiteId, $item->getData('website_ids'))) { $websiteUniqueFlag = false; break; } } if (!$customerGroupUniqueFlag && !$websiteUniqueFlag) { throw new Exception(); } } }