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


PHP AbstractExtensibleModel::beforeSave方法代码示例

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


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

示例1: beforeSave

 /**
  * Processing object before save data
  *
  * @return $this
  */
 public function beforeSave()
 {
     if (!$this->getAttributeGroupCode()) {
         $groupName = $this->getAttributeGroupName();
         if ($groupName) {
             $this->setAttributeGroupCode(trim(preg_replace('/[^a-z0-9]+/', '-', strtolower($groupName)), '-'));
         }
     }
     return parent::beforeSave();
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:15,代码来源:Group.php

示例2: 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:niranjanssiet,项目名称:magento2,代码行数:18,代码来源:Agreement.php

示例3: beforeSave

 /**
  * Processing object before save data
  *
  * @return $this
  */
 public function beforeSave()
 {
     if (!$this->getAttributeGroupCode()) {
         $groupName = $this->getAttributeGroupName();
         if ($groupName) {
             $attributeGroupCode = trim(preg_replace('/[^a-z0-9]+/', '-', strtolower($groupName)), '-');
             if (empty($attributeGroupCode)) {
                 // in the following code md5 is not used for security purposes
                 $attributeGroupCode = md5($groupName);
             }
             $this->setAttributeGroupCode($attributeGroupCode);
         }
     }
     return parent::beforeSave();
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:20,代码来源:Group.php

示例4: beforeSave

 /**
  * @return $this
  */
 public function beforeSave()
 {
     parent::beforeSave();
     $this->getRegion();
     return $this;
 }
开发者ID:opexsw,项目名称:magento2,代码行数:9,代码来源:AbstractAddress.php

示例5: beforeSave

 /**
  * Prepare data before save
  *
  * @return $this
  */
 public function beforeSave()
 {
     /**
      * Currency logic
      *
      * global - currency which is set for default in backend
      * base - currency which is set for current website. all attributes that
      *      have 'base_' prefix saved in this currency
      * quote/order - currency which was selected by customer or configured by
      *      admin for current store. currency in which customer sees
      *      price thought all checkout.
      *
      * Rates:
      *      base_to_global & base_to_quote/base_to_order
      */
     $globalCurrencyCode = $this->_config->getValue(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE, 'default');
     $baseCurrency = $this->getStore()->getBaseCurrency();
     if ($this->hasForcedCurrency()) {
         $quoteCurrency = $this->getForcedCurrency();
     } else {
         $quoteCurrency = $this->getStore()->getCurrentCurrency();
     }
     $this->setGlobalCurrencyCode($globalCurrencyCode);
     $this->setBaseCurrencyCode($baseCurrency->getCode());
     $this->setStoreCurrencyCode($baseCurrency->getCode());
     $this->setQuoteCurrencyCode($quoteCurrency->getCode());
     $this->setBaseToGlobalRate($baseCurrency->getRate($globalCurrencyCode));
     $this->setBaseToQuoteRate($baseCurrency->getRate($quoteCurrency));
     if (!$this->hasChangedFlag() || $this->getChangedFlag() == true) {
         $this->setIsChanged(1);
     } else {
         $this->setIsChanged(0);
     }
     if ($this->_customer) {
         $this->setCustomerId($this->_customer->getId());
     }
     //mark quote if it has virtual products only
     $this->setIsVirtual($this->getIsVirtual());
     parent::beforeSave();
 }
开发者ID:niranjanssiet,项目名称:magento2,代码行数:45,代码来源:Quote.php

示例6: beforeSave

 /**
  * Verify data required for saving
  *
  * @return $this
  */
 public function beforeSave()
 {
     // set parent id
     $this->_verifyPaymentObject();
     if (!$this->getId()) {
         // We need to set order and payment ids only for new transactions
         if (null !== $this->_paymentObject) {
             $this->setPaymentId($this->_paymentObject->getId());
         }
         if (null !== $this->_order) {
             $this->setOrderId($this->_order->getId());
         }
         $this->setCreatedAt($this->_dateFactory->create()->gmtDate());
     }
     return parent::beforeSave();
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:21,代码来源:Transaction.php

示例7: 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->_conditions = null;
     }
     // Serialize actions
     if ($this->getActions()) {
         $this->setActionsSerialized(serialize($this->getActions()->asArray()));
         $this->_actions = null;
     }
     /**
      * 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:Doability,项目名称:magento2dev,代码行数:48,代码来源:AbstractModel.php

示例8: beforeSave

 /**
  * Before save unlock attributes
  *
  * @return \Magento\Catalog\Model\AbstractModel
  */
 public function beforeSave()
 {
     $this->unlockAttributes();
     return parent::beforeSave();
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:10,代码来源:AbstractModel.php

示例9: beforeSave

 /**
  * Specify parent item id before saving data
  *
  * @return $this
  */
 public function beforeSave()
 {
     parent::beforeSave();
     if ($this->getParentItem()) {
         $this->setParentItemId($this->getParentItem()->getId());
     }
     return $this;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:13,代码来源:AbstractItem.php

示例10: beforeSave

 /**
  * Prepare location settings and tax postcode before save rate
  *
  * @return \Magento\Tax\Model\Calculation\Rate
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function beforeSave()
 {
     $isWrongRange = $this->getZipIsRange() && ($this->getZipFrom() === '' || $this->getZipTo() === '');
     $isEmptyValues = $this->getCode() === '' || $this->getTaxCountryId() === '' || $this->getRate() === '' || $this->getTaxPostcode() === '' && !$this->getZipIsRange();
     if ($isEmptyValues || $isWrongRange) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Make sure all required information is valid.'));
     }
     if (!is_numeric($this->getRate()) || $this->getRate() < 0) {
         throw new \Magento\Framework\Exception\LocalizedException(__('The Rate Percent should be a positive number.'));
     }
     if ($this->getZipIsRange()) {
         $zipFrom = $this->getZipFrom();
         $zipTo = $this->getZipTo();
         if (strlen($zipFrom) > 9 || strlen($zipTo) > 9) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Maximum zip code length is 9.'));
         }
         if (!is_numeric($zipFrom) || !is_numeric($zipTo) || $zipFrom < 0 || $zipTo < 0) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Use digits only for the zip code.'));
         }
         if ($zipFrom > $zipTo) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Range To should be equal or greater than Range From.'));
         }
         $this->setTaxPostcode($zipFrom . '-' . $zipTo);
     } else {
         $taxPostCode = $this->getTaxPostcode();
         if (strlen($taxPostCode) > 10) {
             $taxPostCode = substr($taxPostCode, 0, 10);
         }
         $this->setTaxPostcode($taxPostCode)->setZipIsRange(null)->setZipFrom(null)->setZipTo(null);
     }
     parent::beforeSave();
     $country = $this->getTaxCountryId();
     $region = $this->getTaxRegionId();
     /** @var $regionModel \Magento\Directory\Model\Region */
     $regionModel = $this->_regionFactory->create();
     $regionModel->load($region);
     if ($regionModel->getCountryId() != $country) {
         $this->setTaxRegionId('*');
     }
     return $this;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:49,代码来源:Rate.php

示例11: beforeSave

 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function beforeSave()
 {
     parent::beforeSave();
     if ($this->getData('previous_type') != '') {
         $previousType = $this->getData('previous_type');
         /**
          * if previous option has different group from one is came now
          * need to remove all data of previous group
          */
         if ($this->getGroupByType($previousType) != $this->getGroupByType($this->getData('type'))) {
             switch ($this->getGroupByType($previousType)) {
                 case self::OPTION_GROUP_SELECT:
                     $this->unsetData('values');
                     if ($this->getId()) {
                         $this->getValueInstance()->deleteValue($this->getId());
                     }
                     break;
                 case self::OPTION_GROUP_FILE:
                     $this->setData('file_extension', '');
                     $this->setData('image_size_x', '0');
                     $this->setData('image_size_y', '0');
                     break;
                 case self::OPTION_GROUP_TEXT:
                     $this->setData('max_characters', '0');
                     break;
                 case self::OPTION_GROUP_DATE:
                     break;
             }
             if ($this->getGroupByType($this->getData('type')) == self::OPTION_GROUP_SELECT) {
                 $this->setData('sku', '');
                 $this->unsetData('price');
                 $this->unsetData('price_type');
                 if ($this->getId()) {
                     $this->deletePrices($this->getId());
                 }
             }
         }
     }
     return $this;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:44,代码来源:Option.php


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