Ejemplo n.º 1
0
 /**
  * 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();
 }
Ejemplo n.º 2
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();
 }
Ejemplo n.º 3
0
 /**
  * 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();
 }
Ejemplo n.º 4
0
 /**
  * @return $this
  */
 public function beforeSave()
 {
     parent::beforeSave();
     $this->getRegion();
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * 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();
 }
Ejemplo n.º 6
0
 /**
  * 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();
 }
Ejemplo n.º 7
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->_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;
 }
Ejemplo n.º 8
0
 /**
  * Before save unlock attributes
  *
  * @return \Magento\Catalog\Model\AbstractModel
  */
 public function beforeSave()
 {
     $this->unlockAttributes();
     return parent::beforeSave();
 }
Ejemplo n.º 9
0
 /**
  * Specify parent item id before saving data
  *
  * @return $this
  */
 public function beforeSave()
 {
     parent::beforeSave();
     if ($this->getParentItem()) {
         $this->setParentItemId($this->getParentItem()->getId());
     }
     return $this;
 }
Ejemplo n.º 10
0
 /**
  * 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;
 }
Ejemplo n.º 11
0
 /**
  * {@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;
 }