当前位置: 首页>>代码示例>>PHP>>正文


PHP AbstractModel::beforeSave方法代码示例

本文整理汇总了PHP中Magento\Framework\Model\AbstractModel::beforeSave方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractModel::beforeSave方法的具体用法?PHP AbstractModel::beforeSave怎么用?PHP AbstractModel::beforeSave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Model\AbstractModel的用法示例。


在下文中一共展示了AbstractModel::beforeSave方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: beforeSave

 /**
  * BeforeSave actions
  *
  * @return $this
  */
 public function beforeSave()
 {
     $this->setUpdatedAt(time());
     $this->validate();
     parent::beforeSave();
     return $this;
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:12,代码来源:Consumer.php

示例2: beforeSave

 /**
  * Check order id
  *
  * @return $this
  */
 public function beforeSave()
 {
     if (null == $this->getOrderId()) {
         throw new \Exception(__('Order id cannot be null'));
     }
     return parent::beforeSave();
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:12,代码来源:Purchased.php

示例3: beforeSave

 /**
  * @return $this
  */
 public function beforeSave()
 {
     parent::beforeSave();
     if ($this->getAddress()) {
         $this->setAddressId($this->getAddress()->getId());
     }
     return $this;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:11,代码来源:Rate.php

示例4: beforeSave

 /**
  * 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.'));
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:14,代码来源:Block.php

示例5: beforeSave

 /**
  * 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;
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:14,代码来源:Importer.php

示例6: beforeSave

 /**
  * 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;
 }
开发者ID:dotmailer,项目名称:dotmailer-magento2-extension,代码行数:16,代码来源:Review.php

示例7: beforeSave

 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;
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:12,代码来源:Rules.php

示例8: beforeSave

 /**
  * 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();
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:18,代码来源:Agreement.php

示例9: 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;
 }
开发者ID:nja78,项目名称:magento2,代码行数:22,代码来源:AbstractIndex.php

示例10: beforeSave

 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();
 }
开发者ID:mrtuvn,项目名称:m2ce.dev,代码行数:18,代码来源:Banner.php

示例11: 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;
 }
开发者ID:nja78,项目名称:magento2,代码行数:48,代码来源:AbstractModel.php

示例12: beforeSave

 /**
  * Before theme save
  *
  * @return $this
  */
 public function beforeSave()
 {
     $this->_validate();
     return parent::beforeSave();
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:10,代码来源:Theme.php

示例13: 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();
 }
开发者ID:nja78,项目名称:magento2,代码行数:16,代码来源:Settlement.php

示例14: 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();
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:12,代码来源:File.php

示例15: 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;
 }
开发者ID:nja78,项目名称:magento2,代码行数:26,代码来源:Session.php


注:本文中的Magento\Framework\Model\AbstractModel::beforeSave方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。