예제 #1
0
 /**
  * BeforeSave actions
  *
  * @return $this
  */
 public function beforeSave()
 {
     $this->setUpdatedAt(time());
     $this->validate();
     parent::beforeSave();
     return $this;
 }
예제 #2
0
 /**
  * Check order id
  *
  * @return $this
  */
 public function beforeSave()
 {
     if (null == $this->getOrderId()) {
         throw new \Exception(__('Order id cannot be null'));
     }
     return parent::beforeSave();
 }
예제 #3
0
 /**
  * @return $this
  */
 public function beforeSave()
 {
     parent::beforeSave();
     if ($this->getAddress()) {
         $this->setAddressId($this->getAddress()->getId());
     }
     return $this;
 }
예제 #4
0
 /**
  * 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.'));
 }
예제 #5
0
 /**
  * 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;
 }
예제 #7
0
 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;
 }
예제 #8
0
 /**
  * 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();
 }
예제 #9
0
 /**
  * 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;
 }
예제 #10
0
파일: Banner.php 프로젝트: mrtuvn/m2ce.dev
 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();
 }
예제 #11
0
 /**
  * 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;
 }
예제 #12
0
 /**
  * Before theme save
  *
  * @return $this
  */
 public function beforeSave()
 {
     $this->_validate();
     return parent::beforeSave();
 }
예제 #13
0
 /**
  * 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();
 }
예제 #14
0
 /**
  * Prepare file before it will be saved
  *
  * @return $this
  */
 public function beforeSave()
 {
     $fileService = $this->getCustomizationService();
     $fileService->prepareFile($this);
     $fileService->save($this);
     return parent::beforeSave();
 }
예제 #15
0
파일: Session.php 프로젝트: nja78/magento2
 /**
  * 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;
 }
예제 #16
0
 /**
  * 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)));
 }
예제 #17
0
 /**
  * Before Event save process
  *
  * @return $this
  */
 public function beforeSave()
 {
     $date = $this->_dateFactory->create();
     $this->setLoggedAt($date->gmtDate());
     return parent::beforeSave();
 }
예제 #18
0
 /**
  * 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();
 }
예제 #19
0
 /**
  * Initialize item identifier before save data
  *
  * @return $this
  */
 public function beforeSave()
 {
     if ($this->getItem()) {
         $this->setWishlistItemId($this->getItem()->getId());
     }
     return parent::beforeSave();
 }
예제 #20
0
 /**
  * Prepare data before save
  *
  * @return $this
  */
 public function beforeSave()
 {
     $this->_prepareData();
     return parent::beforeSave();
 }
예제 #21
0
 /**
  * Processing object before save data
  *
  * @return $this
  */
 public function beforeSave()
 {
     $this->setUpdated(time());
     return parent::beforeSave();
 }
예제 #22
0
 /**
  * Set date of last update for wishlist
  *
  * @return $this
  */
 public function beforeSave()
 {
     parent::beforeSave();
     $this->setUpdatedAt($this->_date->gmtDate());
     return $this;
 }
예제 #23
0
 /**
  * Set current updated date
  *
  * @return \Magento\Framework\Model\AbstractModel
  */
 public function beforeSave()
 {
     $this->setUpdatedAt($this->_dateTime->formatDate(time()));
     return parent::beforeSave();
 }
예제 #24
0
 /**
  * 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();
 }
예제 #25
0
 /**
  * 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();
 }
예제 #26
0
 /**
  * Set current store before save
  *
  * @return $this
  */
 public function beforeSave()
 {
     parent::beforeSave();
     if (!$this->hasStoreId()) {
         $this->setStoreId($this->_storeManager->getStore()->getId());
     }
     return $this;
 }
예제 #27
0
파일: Item.php 프로젝트: vasiljok/magento2
 /**
  * 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;
 }
예제 #28
0
 /**
  * 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();
 }
예제 #29
0
파일: User.php 프로젝트: razbakov/magento2
    /**
     * 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();
    }
예제 #30
0
파일: Sitemap.php 프로젝트: nja78/magento2
 /**
  * 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();
 }