Пример #1
0
 /**
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Core_Model_Resource_Db_Abstract
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if ($object->isObjectNew()) {
         $object->setCreatedAt($this->formatDate(true));
     }
     return parent::_beforeSave($object);
 }
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if ($object->isObjectNew() && !$object->hasCreatedAt()) {
         $object->setCreatedAt(Mage::getSingleton('core/date')->gmtDate());
     }
     $object->setUpdatedAt(Mage::getSingleton('core/date')->gmtDate());
     if (is_array($object->getAttr())) {
         $object->setAttr(serialize($object->getAttr()));
     }
     if (!$object->getChildrenCount()) {
         $object->setChildrenCount(0);
     }
     if ($object->getLevel() === null) {
         $object->setLevel(1);
     }
     if (!$object->getId()) {
         $object->setPosition($this->_getMaxPosition($object->getPath()) + 1);
         $path = explode('/', $object->getPath());
         $level = count($path);
         $object->setLevel($level + 1);
         if ($object->getParentId() == null) {
             $object->setLevel(1);
         }
         $object->setPath($object->getPath() . '/');
         $toUpdateChild = explode('/', $object->getPath());
         $this->_getWriteAdapter()->update($this->getTable('item'), array('children_count' => new Zend_Db_Expr('children_count + 1')), array('item_id IN(?)' => $toUpdateChild));
     }
     if ($object->getParentId() == 0) {
         $object->setParentId(null);
     }
     return parent::_beforeSave($object);
 }
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if ($object->isObjectNew() && !$object->hasCreatedAt()) {
         $object->setCreatedAt(Mage::getSingleton('core/date')->gmtDate());
     }
     return parent::_beforeSave($object);
 }
Пример #4
0
 /**
  * Check before save is object is new and set a flag
  * 
  * @param Mage_Core_Model_Abstract $object
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if ($object->isObjectNew() && $object->getSaveMzaxGoalReferences() === null) {
         // only if object is new
         $object->setSaveMzaxGoalReferences(true);
     }
 }
Пример #5
0
 /**
  * Set and update created at and updated at dates before saving the model.
  *
  * @param Mage_Core_Model_Abstract $object
  * @return array
  */
 protected function _prepareDataForSave(Mage_Core_Model_Abstract $object)
 {
     if (!$object->getId() || $object->isObjectNew()) {
         $object->setCreatedAt(now());
     }
     $object->setUpdatedAt(now());
     $data = parent::_prepareDataForSave($object);
     return $data;
 }
Пример #6
0
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if ($object->isObjectNew() && !$object->hasCreatedAt()) {
         $object->setCreatedAt(Mage::getSingleton('core/date')->gmtDate());
     }
     $object->setUpdatedAt(Mage::getSingleton('core/date')->gmtDate());
     Mage::helper('feedexport/format')->preparePostData($object);
     return parent::_beforeSave($object);
 }
Пример #7
0
 /**
  * Set template type, added at and modified at time
  *
  * @param Mage_Core_Model_Email_Template $object
  * @return Mage_Core_Model_Resource_Email_Template
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if ($object->isObjectNew()) {
         $object->setCreatedAt($this->formatDate(true));
     }
     $object->setModifiedAt($this->formatDate(true));
     $object->setTemplateType((int) $object->getTemplateType());
     return parent::_beforeSave($object);
 }
 /**
  * Process category data before saving
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Zeon_Faq_Model_Mysql4_Category
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     // modify create / update dates
     if ($object->isObjectNew() && !$object->hasCreationTime()) {
         $object->setCreationTime(Mage::getSingleton('core/date')->gmtDate());
     }
     $object->setUpdateTime(Mage::getSingleton('core/date')->gmtDate());
     return parent::_beforeSave($object);
 }
Пример #9
0
 /**
  * Prepare object data for saving
  *
  * @param Mage_Core_Model_Email_Queue|Mage_Core_Model_Abstract $object
  * @return Mage_Core_Model_Resource_Email_Queue
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if ($object->isObjectNew()) {
         $object->setCreatedAt($this->formatDate(true));
     }
     $object->setMessageBodyHash(md5($object->getMessageBody()));
     $object->setMessageParameters(serialize($object->getMessageParameters()));
     return parent::_beforeSave($object);
 }
Пример #10
0
 /**
  * Prepare data for save
  *
  * @param Mage_Core_Model_Abstract $object
  * @return array
  */
 protected function _prepareDataForSave(Mage_Core_Model_Abstract $object)
 {
     $currentTime = Varien_Date::now();
     if ((!$object->getId() || $object->isObjectNew()) && !$object->getCreatedAt()) {
         $object->setCreatedAt($currentTime);
     }
     $object->setUpdatedAt($currentTime);
     $data = parent::_prepareDataForSave($object);
     return $data;
 }
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if (!$object->getLevel()) {
         $object->getLevel(Mirasvit_MstCore_Model_Logger::LOG_LEVEL_NOTICE);
     }
     if ($object->isObjectNew() && !$object->hasCreatedAt()) {
         $object->setCreatedAt(Mage::getSingleton('core/date')->gmtDate());
     }
     return parent::_beforeSave($object);
 }
Пример #12
0
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if ($object->isObjectNew() && !$object->hasCreatedAt()) {
         $object->setCreatedAt(Mage::getSingleton('core/date')->gmtDate());
     }
     $object->setUpdatedAt(Mage::getSingleton('core/date')->gmtDate());
     $conditions = $object->getCondition();
     unset($conditions['CID']);
     $object->setConditionsSerialized(serialize($conditions));
     return parent::_beforeSave($object);
 }
Пример #13
0
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if ($object->isObjectNew() && !$object->hasCreatedAt()) {
         $object->setCreatedAt(Mage::getSingleton('core/date')->gmtDate());
     }
     $object->setUpdatedAt(Mage::getSingleton('core/date')->gmtDate());
     if ($object->getData('mapping') && is_array($object->getData('mapping'))) {
         $object->setData('mapping_serialized', serialize($object->getData('mapping')));
     }
     return parent::_beforeSave($object);
 }
Пример #14
0
 /**
  * Process popup data before saving
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Etailers_Popup_Model_Resource_Popup
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     /*
      * For two attributes which represent timestamp data in DB
      * we should make converting such as:
      * If they are empty we need to convert them into DB
      * type NULL so in DB they will be empty and not some default value
      */
     // modify create / update dates
     if ($object->isObjectNew() && !$object->hasCreationTime()) {
         $object->setCreationTime(Mage::getSingleton('core/date')->gmtDate());
     }
     $object->setUpdateTime(Mage::getSingleton('core/date')->gmtDate());
     return parent::_beforeSave($object);
 }
Пример #15
0
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if ($object->isObjectNew() && !$object->hasCreatedAt()) {
         $object->setCreatedAt(Mage::getSingleton('core/date')->gmtDate());
     }
     if (!$object->hasStatus()) {
         $object->setStatus(Mirasvit_Email_Model_Queue::STATUS_PENDING)->setStatusMessage('Assignment of default status');
     }
     if ($object->hasData('args')) {
         $object->setArgsSerialized(serialize($object->getData('args')));
     }
     $this->_processHistory($object);
     $object->setUniqKeyMd5(md5($object->getUniqKey()));
     $object->setUpdatedAt(Mage::getSingleton('core/date')->gmtDate());
     return parent::_beforeSave($object);
 }
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if ($object->isObjectNew() && !$object->hasCreatedAt()) {
         $object->setCreatedAt(Mage::getSingleton('core/date')->gmtDate());
     }
     if (is_array($object->getData('store_ids'))) {
         $object->setData('store_ids', implode(',', $object->getData('store_ids')));
     }
     if (is_array($object->getData('cancellation_event'))) {
         $object->setData('cancellation_event', implode(',', $object->getData('cancellation_event')));
     }
     $object->setUpdatedAt(Mage::getSingleton('core/date')->gmtDate());
     if ($object->hasData('rule')) {
         $this->_saveRule($object);
     }
     return parent::_beforeSave($object);
 }
Пример #17
0
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if ($object->isObjectNew() && !$object->hasCreatedAt()) {
         $object->setCreatedAt(Mage::getSingleton('core/date')->gmtDate());
     }
     $object->setUpdatedAt(Mage::getSingleton('core/date')->gmtDate());
     if ($object->getActiveTo()) {
         $object->setActiveTo(str_replace('00:00:00', '23:59:59', $object->getActiveTo()));
         //include full day
     }
     if ($object->getActiveTo() == '') {
         $object->setActiveTo(null);
     }
     if ($object->getActiveFrom() == '') {
         $object->setActiveFrom(null);
     }
     return parent::_beforeSave($object);
 }
Пример #18
0
 /**
  * Perform actions after object save.
  *
  * @param Varien_Object $object The previously created link
  * @return Faett_Package_Model_Mysql4_Link The instance
  */
 protected function _afterSave(Mage_Core_Model_Abstract $object)
 {
     // check if a new Link was saved
     if ($object->isObjectNew()) {
         // if yes, initialize the model
         $linkUpdate = Mage::getModel('channel/link_update');
         $linkUpdate->loadByLinkIdFk($linkId = $object->getLinkId());
         // check if the update link was already set
         if (is_null($linkUpdate->getId())) {
             // if not, create a new link update entry
             $linkUpdate->setLinkIdFk($linkId);
             $linkUpdate->setCreatedAt(date('Y-m-d H:i:s'));
             $linkUpdate->save();
         }
     }
     // call the parent method
     return parent::_afterSave($object);
 }
Пример #19
0
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     /*
      * For two attributes which represent timestamp data in DB
      * we should make converting such as:
      * If they are empty we need to convert them into DB
      * type NULL so in DB they will be empty and not some default value
      */
     foreach (array('custom_theme_from', 'custom_theme_to') as $field) {
         $value = !$object->getData($field) ? null : $object->getData($field);
         $object->setData($field, $this->formatDate($value));
     }
     // modify create / update dates
     if ($object->isObjectNew() && !$object->hasCreationTime()) {
         $object->setCreationTime(Mage::getSingleton('core/date')->gmtDate());
     }
     $object->setUpdateTime(Mage::getSingleton('core/date')->gmtDate());
     return parent::_beforeSave($object);
 }
Пример #20
0
 /**
  * @param Goodahead_Etm_Model_Attribute|Mage_Core_Model_Abstract $object
  * @return Mage_Eav_Model_Resource_Entity_Attribute
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if ($object->isObjectNew()) {
         /* @var $helper Mage_Catalog_Helper_Product */
         $helper = Mage::helper('goodahead_etm');
         if (!$object->hasSourceModel()) {
             $object->setSourceModel($helper->getAttributeSourceModelByInputType($object->getFrontendInput()));
         }
         if (!$object->hasBackendModel()) {
             $object->setBackendModel($helper->getAttributeBackendModelByInputType($object->getFrontendInput()));
         }
         if (!$object->hasFrontendModel()) {
             $object->setFrontendModel($helper->getAttributeFrontendModelByInputType($object->getFrontendInput()));
         }
         if (!$object->hasBackendType()) {
             $object->setBackendType($object->getBackendTypeByInput($object->getFrontendInput()));
         }
     }
     return parent::_beforeSave($object);
 }
Пример #21
0
 /**
  * Before save.
  *
  * @param Mirasvit_FeedExport_Model_Feed $object
  *
  * @return $this
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if ($object->isObjectNew() && !$object->hasCreatedAt()) {
         $object->setCreatedAt(Mage::getSingleton('core/date')->gmtDate());
     }
     $object->setUpdatedAt(Mage::getSingleton('core/date')->gmtDate());
     if (!$object->getIsMassStatus()) {
         Mage::helper('feedexport/format')->preparePostData($object);
         if (is_array($object->getCronDay())) {
             $object->setCronDay(implode(',', $object->getCronDay()));
         }
         if (is_array($object->getCronTime())) {
             $object->setCronTime(implode(',', $object->getCronTime()));
         }
         if (is_array($object->getNotificationEvents())) {
             $object->setNotificationEvents(implode(',', $object->getNotificationEvents()));
         }
     }
     $this->saveRules($object);
     return parent::_beforeSave($object);
 }
Пример #22
0
 /**
  * Set created/modified values before user save
  *
  * @param Mage_Core_Model_Abstract $user
  * @return Mage_Admin_Model_Resource_User
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $user)
 {
     if ($user->isObjectNew()) {
         $user->setCreated($this->formatDate(true));
     }
     $user->setModified($this->formatDate(true));
     return parent::_beforeSave($user);
 }
 /**
  * Save attribute/form relations after attribute save
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Eav_Model_Resource_Attribute
  */
 protected function _afterSave(Mage_Core_Model_Abstract $object)
 {
     $forms = $object->getData('used_in_forms');
     $adapter = $this->_getWriteAdapter();
     if (is_array($forms)) {
         $where = array('attribute_id=?' => $object->getId());
         $adapter->delete($this->_getFormAttributeTable(), $where);
         $data = array();
         foreach ($forms as $formCode) {
             $data[] = array('form_code' => $formCode, 'attribute_id' => (int) $object->getId());
         }
         if ($data) {
             $adapter->insertMultiple($this->_getFormAttributeTable(), $data);
         }
     }
     // update sort order
     if (!$object->isObjectNew() && $object->dataHasChangedFor('sort_order')) {
         $data = array('sort_order' => $object->getSortOrder());
         $where = array('attribute_id=?' => (int) $object->getId());
         $adapter->update($this->getTable('eav/entity_attribute'), $data, $where);
     }
     // save scope attributes
     $websiteId = (int) $object->getWebsite()->getId();
     if ($websiteId) {
         $table = $this->_getEavWebsiteTable();
         $describe = $this->_getReadAdapter()->describeTable($table);
         $data = array();
         if (!$object->getScopeWebsiteId() || $object->getScopeWebsiteId() != $websiteId) {
             $data = $this->getScopeValues($object);
         }
         $data['attribute_id'] = (int) $object->getId();
         $data['website_id'] = (int) $websiteId;
         unset($describe['attribute_id']);
         unset($describe['website_id']);
         $updateColumns = array();
         foreach (array_keys($describe) as $columnName) {
             $data[$columnName] = $object->getData('scope_' . $columnName);
             $updateColumns[] = $columnName;
         }
         $adapter->insertOnDuplicate($table, $data, $updateColumns);
     }
     return parent::_afterSave($object);
 }
Пример #24
0
 /**
  * Save attribute options
  *
  * @param Mage_Eav_Model_Entity_Attribute|Mage_Core_Model_Abstract $object
  * @return Mage_Eav_Model_Resource_Entity_Attribute
  */
 protected function _saveOption(Mage_Core_Model_Abstract $object)
 {
     $option = $object->getOption();
     if (!is_array($option)) {
         return $this;
     }
     /* System attribute options are permanent, which of them is default can be changed only */
     if (!$object->getIsUserDefined() && !$object->getCanManageOptionLabels() && !$object->isObjectNew()) {
         $defaultValue = $object->getDefault() ?: array();
     } elseif (isset($option['value'])) {
         if (!is_array($object->getDefault())) {
             $object->setDefault(array());
         }
         $defaultValue = $this->_processUserDefinedAttributeOptions($object, $option);
     } else {
         $defaultValue = null;
     }
     $this->_saveDefaultValue($object, $defaultValue);
     return $this;
 }
Пример #25
0
 /**
  * Load mongo data into a model using the schema mappings
  *
  * @param Mage_Core_Model_Abstract $object
  * @param array $data
  * @param boolean $original   Is the data from the database?
  * @throws Exception
  */
 public function hydrate(Mage_Core_Model_Abstract $object, array $data, $original = FALSE)
 {
     $converter = $this->getMongoToPhpConverter();
     foreach ($this->getFieldMappings() as $field => $mapping) {
         if (!array_key_exists($field, $data)) {
             continue;
         }
         $value = $data[$field];
         if ($value !== NULL) {
             $type = isset($mapping->type) ? (string) $mapping->type : 'string';
             if ($type == 'embedded') {
                 $model = $object->getDataUsingMethod($field);
                 if (!$model instanceof Cm_Mongo_Model_Abstract) {
                     throw new Exception('Invalid embedded object instance for ' . $field . '.');
                 }
                 // Allow data to be hydrated from Varien_Object
                 if ($value instanceof Varien_Object) {
                     $value = $value->getData();
                 }
                 $model->getResource()->hydrate($model, $value, $original);
             } elseif ($type == 'embeddedSet') {
                 // Allow data to be hydrated from Varien_Data_Collection
                 if ($value instanceof Varien_Data_Collection) {
                     $value = $value->walk('getData');
                 }
                 /* @var $set Cm_Mongo_Model_Resource_Collection_Embedded */
                 if (!$object->getData($field)) {
                     $set = $object->getDataUsingMethod($field);
                     foreach ($value as $itemData) {
                         $model = $set->getNewEmptyItem();
                         $model->getResource()->hydrate($model, $itemData, $original);
                         $set->addItem($model);
                     }
                 } else {
                     $set = $object->getData($field);
                     foreach ($value as $index => $itemData) {
                         $item = $set->getItemById($index);
                         if (!$item) {
                             $item = Mage::getModel((string) $mapping->model);
                         }
                         $item->getResource()->hydrate($item, $itemData, $original);
                     }
                 }
             } else {
                 $value = $converter->{$type}($mapping, $value);
                 $object->setDataUsingMethod($field, $value);
             }
         } else {
             $object->setData($field, NULL);
         }
     }
     if ($original) {
         $object->isObjectNew(FALSE);
         $object->setOrigData();
         $this->_afterLoad($object);
     }
 }