Example #1
0
 /**
  * After save process
  *
  * @return $this
  */
 public function afterSave()
 {
     parent::afterSave();
     $this->_getResource()->saveLabel($this);
     $this->_getResource()->savePrices($this);
     return $this;
 }
Example #2
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();
 }
Example #3
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();
 }
Example #4
0
 /**
  * Retrieve data
  *
  * @param string $key
  * @param mixed $index
  * @return mixed
  */
 public function getData($key = '', $index = null)
 {
     if ('cc_number' === $key) {
         if (empty($this->_data['cc_number']) && !empty($this->_data['cc_number_enc'])) {
             $this->_data['cc_number'] = $this->decrypt($this->getCcNumberEnc());
         }
     }
     if ('cc_cid' === $key) {
         if (empty($this->_data['cc_cid']) && !empty($this->_data['cc_cid_enc'])) {
             $this->_data['cc_cid'] = $this->decrypt($this->getCcCidEnc());
         }
     }
     return parent::getData($key, $index);
 }
Example #5
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();
 }
Example #6
0
 /**
  * Validate tax class can be deleted
  *
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function beforeDelete()
 {
     $this->checkClassCanBeDeleted();
     return parent::beforeDelete();
 }
 /**
  * @param \Magento\Framework\Model\Context $context
  * @param \Magento\Framework\Registry $registry
  * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
  * @param AttributeValueFactory $customAttributeFactory
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  * @param array $data
  */
 public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [])
 {
     $this->_storeManager = $storeManager;
     parent::__construct($context, $registry, $extensionFactory, $customAttributeFactory, $resource, $resourceCollection, $data);
     $this->setIncludePath();
 }
Example #8
0
 /**
  * Rewrite in order to clear configuration cache
  *
  * @return $this
  */
 public function afterDelete()
 {
     $this->_storeManager->reinitStores();
     parent::afterDelete();
     return $this;
 }
Example #9
0
 /**
  * @inheritdoc
  */
 public function __wakeup()
 {
     parent::__wakeup();
     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
     $this->metadataPool = $objectManager->get(MetadataPool::class);
 }
Example #10
0
 /**
  * @return \Magento\Framework\Model\AbstractModel
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function afterSave()
 {
     $this->getValueInstance()->unsetValues();
     if (is_array($this->getData('values'))) {
         foreach ($this->getData('values') as $value) {
             $this->getValueInstance()->addValue($value);
         }
         $this->getValueInstance()->setOption($this)->saveValues();
     } elseif ($this->getGroupByType($this->getType()) == self::OPTION_GROUP_SELECT) {
         throw new LocalizedException(__('Select type options required values rows.'));
     }
     return parent::afterSave();
 }
Example #11
0
 /**
  * Rewrite in order to clear configuration cache
  *
  * @return $this
  */
 public function afterDelete()
 {
     parent::afterDelete();
     $this->_configCacheType->clean();
     return $this;
 }
Example #12
0
 /**
  * @param \Magento\Framework\Model\Context $context
  * @param \Magento\Framework\Registry $registry
  * @param ExtensionAttributesFactory $extensionFactory
  * @param AttributeValueFactory $customAttributeFactory
  * @param \Magento\Customer\Model\Session $customerSession
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param StockConfigurationInterface $stockConfiguration
  * @param StockRegistryInterface $stockRegistry
  * @param StockItemRepositoryInterface $stockItemRepository
  * @param \Magento\Framework\Model\Resource\AbstractResource $resource
  * @param \Magento\Framework\Data\Collection\Db $resourceCollection
  * @param array $data
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Customer\Model\Session $customerSession, \Magento\Store\Model\StoreManagerInterface $storeManager, StockConfigurationInterface $stockConfiguration, StockRegistryInterface $stockRegistry, StockItemRepositoryInterface $stockItemRepository, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\Db $resourceCollection = null, array $data = [])
 {
     parent::__construct($context, $registry, $extensionFactory, $customAttributeFactory, $resource, $resourceCollection, $data);
     $this->customerSession = $customerSession;
     $this->storeManager = $storeManager;
     $this->stockConfiguration = $stockConfiguration;
     $this->stockRegistry = $stockRegistry;
     $this->stockItemRepository = $stockItemRepository;
 }
 /**
  * @param string[] $attributesAsArray
  * @param \Magento\Framework\Model\AbstractExtensibleModel $model
  * @return \Magento\Framework\Api\AttributeInterface[]
  */
 protected function addCustomAttributesToModel($attributesAsArray, $model)
 {
     $addedAttributes = [];
     foreach ($attributesAsArray as $attributeCode => $attributeValue) {
         $addedAttributes[$attributeCode] = new AttributeValue([AttributeValue::ATTRIBUTE_CODE => $attributeCode, AttributeValue::VALUE => $attributeValue]);
     }
     $model->setData(array_merge($model->getData(), [\Magento\Framework\Api\CustomAttributesDataInterface::CUSTOM_ATTRIBUTES => $addedAttributes]));
     return $addedAttributes;
 }
 /**
  * @return $this
  */
 public function beforeDelete()
 {
     $this->_configDataResource->clearScopeData(\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $this->getStoreIds());
     return parent::beforeDelete();
 }
 /**
  * @inheritdoc
  */
 public function __wakeup()
 {
     parent::__wakeup();
     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
     $this->_eavConfig = $objectManager->get(\Magento\Eav\Model\Config::class);
     $this->_eavTypeFactory = $objectManager->get(\Magento\Eav\Model\Entity\TypeFactory::class);
     $this->_storeManager = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class);
     $this->_resourceHelper = $objectManager->get(\Magento\Eav\Model\ResourceModel\Helper::class);
     $this->_universalFactory = $objectManager->get(\Magento\Framework\Validator\UniversalFactory::class);
     $this->optionDataFactory = $objectManager->get(\Magento\Eav\Api\Data\AttributeOptionInterfaceFactory::class);
     $this->dataObjectProcessor = $objectManager->get(\Magento\Framework\Reflection\DataObjectProcessor::class);
     $this->dataObjectHelper = $objectManager->get(\Magento\Framework\Api\DataObjectHelper::class);
 }
Example #16
0
 /**
  * After rule delete
  * Re-declared for dispatch tax_settings_change_after event
  *
  * @return $this
  */
 public function afterDelete()
 {
     $this->_eventManager->dispatch('tax_settings_change_after');
     return parent::afterDelete();
 }
Example #17
0
 /**
  * @param \Magento\Framework\Model\Context $context
  * @param \Magento\Framework\Registry $registry
  * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
  * @param AttributeValueFactory $customAttributeFactory
  * @param Resource\Message $resource
  * @param \Magento\Framework\Data\Collection\Db $resourceCollection
  * @param TypeFactory $typeFactory
  * @param array $data
  */
 public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\GiftMessage\Model\Resource\Message $resource, \Magento\Framework\Data\Collection\Db $resourceCollection, \Magento\GiftMessage\Model\TypeFactory $typeFactory, array $data = [])
 {
     $this->_typeFactory = $typeFactory;
     parent::__construct($context, $registry, $extensionFactory, $customAttributeFactory, $resource, $resourceCollection, $data);
 }
Example #18
0
 /**
  * Before save unlock attributes
  *
  * @return \Magento\Catalog\Model\AbstractModel
  */
 public function beforeSave()
 {
     $this->unlockAttributes();
     return parent::beforeSave();
 }
Example #19
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();
 }
 /**
  * Get resource instance
  *
  * @return \Magento\Framework\Model\ResourceModel\Db\AbstractDb
  */
 protected function _getResource()
 {
     return $this->_resource ?: parent::_getResource();
 }
Example #21
0
 /**
  * Trigger collect totals after loading, if required
  *
  * @return $this
  */
 protected function _afterLoad()
 {
     // collect totals and save me, if required
     if (1 == $this->getData('trigger_recollect')) {
         $this->collectTotals()->save();
     }
     return parent::_afterLoad();
 }
Example #22
0
 /**
  * After save process
  *
  * @return $this
  */
 public function afterSave()
 {
     $this->getResource()->saveItemTitle($this);
     return parent::afterSave();
 }
Example #23
0
 /**
  * @param \ShipperHQ\Shipper\Model\ResourceModel\Quote\Packages\CollectionFactory $quotePackageCollectionFactory
  * @param \Magento\Framework\Model\Context $context
  * @param \Magento\Framework\Registry $registry
  * @param ExtensionAttributesFactory $extensionFactory
  * @param AttributeValueFactory $customAttributeFactory
  * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  * @param array $data
  */
 public function __construct(\ShipperHQ\Shipper\Model\ResourceModel\Quote\Packages\CollectionFactory $quotePackageCollectionFactory, \Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [])
 {
     parent::__construct($context, $registry, $extensionFactory, $customAttributeFactory, $resource, $resourceCollection, $data);
     $this->quotePackageCollection = $quotePackageCollectionFactory->create();
 }
Example #24
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;
 }
Example #25
0
 /**
  * @param \Magento\Framework\Model\Context $context
  * @param \Magento\Framework\Registry $registry
  * @param ExtensionAttributesFactory $extensionFactory
  * @param AttributeValueFactory $customAttributeFactory
  * @param array $options
  * @param \Magento\Framework\Model\Resource\AbstractResource $resource
  * @param \Magento\Framework\Data\Collection\Db $resourceCollection
  * @param array $data
  */
 public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, array $options, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\Db $resourceCollection = null, array $data = [])
 {
     $this->options = $options;
     parent::__construct($context, $registry, $extensionFactory, $customAttributeFactory, $resource, $resourceCollection, $data);
 }
Example #26
0
 /**
  * @param Context $context
  * @param Registry $registry
  * @param ExtensionAttributesFactory $extensionFactory
  * @param AttributeValueFactory $customAttributeFactory
  * @param AbstractResource|null $resource
  * @param AbstractDb|null $resourceCollection
  * @param FileProcessor $fileProcessor
  * @param array $data
  */
 public function __construct(Context $context, Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, FileProcessor $fileProcessor, AbstractResource $resource = null, AbstractDb $resourceCollection = null, array $data = [])
 {
     $this->fileProcessor = $fileProcessor;
     parent::__construct($context, $registry, $extensionFactory, $customAttributeFactory, $resource, $resourceCollection, $data);
 }
 /**
  * @param \Magento\Framework\Model\Context $context
  * @param \Magento\Framework\Registry $registry
  * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
  * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
  * @param \Magento\Payment\Helper\Data $paymentData
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param Logger $logger
  * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  * @param array $data
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, \Magento\Payment\Helper\Data $paymentData, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Payment\Model\Method\Logger $logger, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [])
 {
     parent::__construct($context, $registry, $extensionFactory, $customAttributeFactory, $resource, $resourceCollection, $data);
     $this->_paymentData = $paymentData;
     $this->_scopeConfig = $scopeConfig;
     $this->logger = $logger;
     $this->initializeData($data);
 }
Example #28
0
 /**
  * Rewrite in order to clear configuration cache
  *
  * @return $this
  */
 public function afterDelete()
 {
     parent::afterDelete();
     $this->_configCacheType->clean();
     if ($this->getId() === $this->getGroup()->getDefaultStoreId()) {
         $ids = $this->getGroup()->getStoreIds();
         if (!empty($ids) && count($ids) > 1) {
             unset($ids[$this->getId()]);
             $defaultId = current($ids);
         } else {
             $defaultId = null;
         }
         $this->getGroup()->setDefaultStoreId($defaultId);
         $this->getGroup()->save();
     }
     return $this;
 }
Example #29
0
 /**
  * @return $this
  */
 public function beforeSave()
 {
     parent::beforeSave();
     $this->getRegion();
     return $this;
 }
Example #30
0
 /**
  * Initialize resource model
  *
  * @return void
  */
 protected function _construct()
 {
     $this->_init('Magento\\Bundle\\Model\\ResourceModel\\Option');
     parent::_construct();
 }