/** * BeforeSave actions * * @return $this */ public function beforeSave() { $this->setUpdatedAt(time()); $this->validate(); parent::beforeSave(); return $this; }
/** * Check order id * * @return $this */ public function beforeSave() { if (null == $this->getOrderId()) { throw new \Exception(__('Order id cannot be null')); } return parent::beforeSave(); }
/** * @return $this */ public function beforeSave() { parent::beforeSave(); if ($this->getAddress()) { $this->setAddressId($this->getAddress()->getId()); } return $this; }
/** * Prevent blocks recursion * * @return AbstractModel * @throws \Magento\Framework\Exception\LocalizedException */ public function beforeSave() { $needle = 'block_id="' . $this->getId() . '"'; if (false == strstr($this->getContent(), $needle)) { return parent::beforeSave(); } throw new \Magento\Framework\Exception\LocalizedException(__('Make sure that static block content does not reference the block itself.')); }
/** * Prepare data to be saved to database * * @return $this */ public function beforeSave() { parent::beforeSave(); if ($this->isObjectNew()) { $this->setCreatedAt($this->_dateTime->formatDate(true)); } $this->setUpdatedAt($this->_dateTime->formatDate(true)); return $this; }
/** * Prepare data to be saved to database. * * @return $this * @codingStandardsIgnoreStart */ public function beforeSave() { //@codingStandardsIgnoreEnd parent::beforeSave(); if ($this->isObjectNew()) { $this->setCreatedAt($this->dateTime->formatDate(true)); } $this->setUpdatedAt($this->dateTime->formatDate(true)); return $this; }
public function beforeSave() { parent::beforeSave(); if ($this->isObjectNew()) { $this->setCreatedAt(time()); } else { $this->setUpdatedAt(time()); } $this->setCondition(serialize($this->getCondition())); $this->setWebsiteIds(implode(',', $this->getWebsiteIds())); return $this; }
/** * Processing object before save data * * @return $this */ public function beforeSave() { if ($this->getContentHeight() == 0) { $this->setContentHeight(''); //converting zero Content-Height } if ($this->getContentHeight() && !preg_match('/(' . implode("|", $this->allowedCssUnits) . ')/', $this->getContentHeight())) { $contentHeight = $this->getContentHeight() . 'px'; //setting default units for Content-Height $this->setContentHeight($contentHeight); } return parent::beforeSave(); }
/** * Prepare customer/visitor, store data before save * * @return $this */ public function beforeSave() { parent::beforeSave(); if (!$this->hasVisitorId()) { $this->setVisitorId($this->getVisitorId()); } if (!$this->hasCustomerId()) { $this->setCustomerId($this->getCustomerId()); } if (!$this->hasStoreId()) { $this->setStoreId($this->getStoreId()); } if (!$this->hasAddedAt()) { $this->setAddedAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)); } return $this; }
public function beforeSave() { if ($this->getStoreViewId()) { $defaultStore = $this->_bannerFactory->create()->setStoreViewId(null)->load($this->getId()); $storeAttributes = $this->getStoreAttributes(); $data = $this->getData(); foreach ($storeAttributes as $attribute) { if (isset($data['use_default']) && isset($data['use_default'][$attribute])) { $this->setData($attribute . '_in_store', false); } else { $this->setData($attribute . '_in_store', true); $this->setData($attribute . '_value', $this->getData($attribute)); } $this->setData($attribute, $defaultStore->getData($attribute)); } } return parent::beforeSave(); }
/** * Prepare data before saving * * @return $this * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function beforeSave() { // Check if discount amount not negative if ($this->hasDiscountAmount()) { if ((int) $this->getDiscountAmount() < 0) { throw new \Magento\Framework\Exception\LocalizedException(__('Please choose a valid discount amount.')); } } // Serialize conditions if ($this->getConditions()) { $this->setConditionsSerialized(serialize($this->getConditions()->asArray())); $this->unsConditions(); } // Serialize actions if ($this->getActions()) { $this->setActionsSerialized(serialize($this->getActions()->asArray())); $this->unsActions(); } /** * Prepare website Ids if applicable and if they were set as string in comma separated format. * Backwards compatibility. */ if ($this->hasWebsiteIds()) { $websiteIds = $this->getWebsiteIds(); if (is_string($websiteIds) && !empty($websiteIds)) { $this->setWebsiteIds(explode(',', $websiteIds)); } } /** * Prepare customer group Ids if applicable and if they were set as string in comma separated format. * Backwards compatibility. */ if ($this->hasCustomerGroupIds()) { $groupIds = $this->getCustomerGroupIds(); if (is_string($groupIds) && !empty($groupIds)) { $this->setCustomerGroupIds(explode(',', $groupIds)); } } parent::beforeSave(); return $this; }
/** * Before theme save * * @return $this */ public function beforeSave() { $this->_validate(); return parent::beforeSave(); }
/** * Stop saving process if file with same report date, account ID and last modified date was already ferched * * @return \Magento\Framework\Model\AbstractModel */ public function beforeSave() { $this->_dataSaveAllowed = true; if ($this->getId()) { if ($this->getLastModified() == $this->getReportLastModified()) { $this->_dataSaveAllowed = false; } } $this->setLastModified($this->getReportLastModified()); return parent::beforeSave(); }
/** * Prepare file before it will be saved * * @return $this */ public function beforeSave() { $fileService = $this->getCustomizationService(); $fileService->prepareFile($this); $fileService->save($this); return parent::beforeSave(); }
/** * Serialize info for Resource Model to save * For new model check and set available cookie key * * @return $this */ public function beforeSave() { parent::beforeSave(); // Setting info $info = []; foreach ($this->getData() as $index => $value) { if (!in_array($index, $this->_unserializableFields)) { $info[$index] = $value; } } $this->setInfo($this->jsonHelper->jsonEncode($info)); if ($this->isObjectNew()) { $this->setWebsiteId($this->_storeManager->getStore()->getWebsiteId()); // Setting cookie key do { $this->setKey($this->mathRandom->getRandomString(self::KEY_LENGTH)); } while (!$this->getResource()->isKeyAllowed($this->getKey())); } return $this; }
/** * Before save, it's overridden just to make data validation on before save event * * @throws \Magento\Framework\Exception\LocalizedException * @return \Magento\Framework\Model\AbstractModel */ public function beforeSave() { if ($this->isValid()) { return parent::beforeSave(); } array_unshift($this->_errors, __('Unable to save Billing Agreement:')); throw new \Magento\Framework\Exception\LocalizedException(__(implode(' ', $this->_errors))); }
/** * Before Event save process * * @return $this */ public function beforeSave() { $date = $this->_dateFactory->create(); $this->setLoggedAt($date->gmtDate()); return parent::beforeSave(); }
/** * Validate data before save data * * @throws \Magento\Framework\Exception\LocalizedException * @return $this */ public function beforeSave() { if (!$this->getTypeId()) { throw new \Magento\Framework\Exception\LocalizedException(__('Invalid form type.')); } if (!$this->getStoreId() && $this->getLabel()) { $this->setStoreLabel($this->getStoreId(), $this->getLabel()); } return parent::beforeSave(); }
/** * Initialize item identifier before save data * * @return $this */ public function beforeSave() { if ($this->getItem()) { $this->setWishlistItemId($this->getItem()->getId()); } return parent::beforeSave(); }
/** * Prepare data before save * * @return $this */ public function beforeSave() { $this->_prepareData(); return parent::beforeSave(); }
/** * Processing object before save data * * @return $this */ public function beforeSave() { $this->setUpdated(time()); return parent::beforeSave(); }
/** * Set date of last update for wishlist * * @return $this */ public function beforeSave() { parent::beforeSave(); $this->setUpdatedAt($this->_date->gmtDate()); return $this; }
/** * Set current updated date * * @return \Magento\Framework\Model\AbstractModel */ public function beforeSave() { $this->setUpdatedAt($this->_dateTime->formatDate(time())); return parent::beforeSave(); }
/** * Processing data before model save * * @return $this */ public function beforeSave() { $data = ['extra' => serialize($this->getExtra())]; if ($this->_willSavePassword()) { $data['password'] = $this->_getEncodedPassword($this->getPassword()); } if ($this->getIsActive() !== null) { $data['is_active'] = intval($this->getIsActive()); } $this->addData($data); return parent::beforeSave(); }
/** * Processing object before save data * * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function beforeSave() { $pageGroupIds = []; $tmpPageGroups = []; $pageGroups = $this->getData('page_groups'); if ($pageGroups) { foreach ($pageGroups as $pageGroup) { if (isset($pageGroup[$pageGroup['page_group']])) { $pageGroupData = $pageGroup[$pageGroup['page_group']]; if ($pageGroupData['page_id']) { $pageGroupIds[] = $pageGroupData['page_id']; } if (in_array($pageGroup['page_group'], ['pages', 'page_layouts'])) { $layoutHandle = $pageGroupData['layout_handle']; } else { $layoutHandle = $this->_layoutHandles[$pageGroup['page_group']]; } if (!isset($pageGroupData['template'])) { $pageGroupData['template'] = ''; } $tmpPageGroup = ['page_id' => $pageGroupData['page_id'], 'group' => $pageGroup['page_group'], 'layout_handle' => $layoutHandle, 'for' => $pageGroupData['for'], 'block_reference' => $pageGroupData['block'], 'entities' => '', 'layout_handle_updates' => [$layoutHandle], 'template' => $pageGroupData['template'] ? $pageGroupData['template'] : '']; if ($pageGroupData['for'] == self::SPECIFIC_ENTITIES) { $layoutHandleUpdates = []; foreach (explode(',', $pageGroupData['entities']) as $entity) { $layoutHandleUpdates[] = str_replace('{{ID}}', $entity, $this->_specificEntitiesLayoutHandles[$pageGroup['page_group']]); } $tmpPageGroup['entities'] = $pageGroupData['entities']; $tmpPageGroup['layout_handle_updates'] = $layoutHandleUpdates; } $tmpPageGroups[] = $tmpPageGroup; } } } if (is_array($this->getData('store_ids'))) { $this->setData('store_ids', implode(',', $this->getData('store_ids'))); } if (is_array($this->getData('widget_parameters'))) { $this->setData('widget_parameters', serialize($this->getData('widget_parameters'))); } $this->setData('page_groups', $tmpPageGroups); $this->setData('page_group_ids', $pageGroupIds); return parent::beforeSave(); }
/** * Set current store before save * * @return $this */ public function beforeSave() { parent::beforeSave(); if (!$this->hasStoreId()) { $this->setStoreId($this->_storeManager->getStore()->getId()); } return $this; }
/** * Check required data * * @return $this */ public function beforeSave() { parent::beforeSave(); // validate required item data $this->validate(); // set current store id if it is not defined if (is_null($this->getStoreId())) { $this->setStoreId($this->_storeManager->getStore()->getId()); } // set current date if added at data is not defined if (is_null($this->getAddedAt())) { $this->setAddedAt($this->_date->gmtDate()); } return $this; }
/** * Validate data before save data * * @throws \Magento\Framework\Exception\LocalizedException * @return $this */ public function beforeSave() { if (!$this->getTypeId()) { throw new LocalizedException(__('Invalid form type.')); } if (!$this->getAttributeId()) { throw new LocalizedException(__('Invalid EAV attribute')); } return parent::beforeSave(); }
/** * Processing data before model save * * @return $this */ public function beforeSave() { $data = [ 'modified' => (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT), 'extra' => serialize($this->getExtra()), ]; if ($this->_willSavePassword()) { $data['password'] = $this->_getEncodedPassword($this->getPassword()); } if ($this->getIsActive() !== null) { $data['is_active'] = intval($this->getIsActive()); } $this->addData($data); return parent::beforeSave(); }
/** * Check sitemap file location and permissions * * @return \Magento\Framework\Model\AbstractModel * @throws \Magento\Framework\Exception\LocalizedException */ public function beforeSave() { $path = $this->getSitemapPath(); /** * Check path is allow */ if ($path && preg_match('#\\.\\.[\\\\/]#', $path)) { throw new \Magento\Framework\Exception\LocalizedException(__('Please define a correct path.')); } /** * Check exists and writable path */ if (!$this->_directory->isExist($path)) { throw new \Magento\Framework\Exception\LocalizedException(__('Please create the specified folder "%1" before saving the sitemap.', $this->_escaper->escapeHtml($this->getSitemapPath()))); } if (!$this->_directory->isWritable($path)) { throw new \Magento\Framework\Exception\LocalizedException(__('Please make sure that "%1" is writable by the web-server.', $this->getSitemapPath())); } /** * Check allow filename */ if (!preg_match('#^[a-zA-Z0-9_\\.]+$#', $this->getSitemapFilename())) { throw new \Magento\Framework\Exception\LocalizedException(__('Please use only letters (a-z or A-Z), numbers (0-9) or underscores (_) in the filename. No spaces or other characters are allowed.')); } if (!preg_match('#\\.xml$#', $this->getSitemapFilename())) { $this->setSitemapFilename($this->getSitemapFilename() . '.xml'); } $this->setSitemapPath(rtrim(str_replace(str_replace('\\', '/', $this->_getBaseDir()), '', $path), '/') . '/'); return parent::beforeSave(); }