Example #1
0
 /**
  * @param array $fixtures
  * @throws \Exception
  */
 public function install(array $fixtures)
 {
     foreach ($fixtures as $fileName) {
         $fileName = $this->fixtureManager->getFixture($fileName);
         if (!file_exists($fileName)) {
             continue;
         }
         $rows = $this->csvReader->getData($fileName);
         $header = array_shift($rows);
         foreach ($rows as $row) {
             $data = [];
             foreach ($row as $key => $value) {
                 $data[$header[$key]] = $value;
             }
             $row = $data;
             $row['customer_group_ids'] = $this->getGroupIds();
             $row['website_ids'] = $this->getWebsiteIds();
             $row['conditions_serialized'] = $this->convertSerializedData($row['conditions_serialized']);
             $row['actions_serialized'] = $this->convertSerializedData($row['actions_serialized']);
             $ruleModel = $this->ruleFactory->create();
             $ruleModel->loadPost($row);
             $ruleModel->save();
         }
     }
     $ruleJob = $this->jobFactory->create();
     $ruleJob->applyAll();
 }
 /**
  * Modify price
  *
  * @param mixed $price
  * @param Product $product
  * @return mixed
  */
 public function modifyPrice($price, Product $product)
 {
     if ($price !== null) {
         $resultPrice = $this->ruleFactory->create()->calcProductPriceRule($product, $price);
         if ($resultPrice !== null) {
             $price = $resultPrice;
         }
     }
     return $price;
 }
 /**
  * {@inheritdoc}
  */
 public function get($ruleId)
 {
     if (!isset($this->rules[$ruleId])) {
         /** @var \Magento\CatalogRule\Model\RuleFactory $rule */
         $rule = $this->ruleFactory->create();
         /* TODO: change to resource model after entity manager will be fixed */
         $rule->load($ruleId);
         if (!$rule->getRuleId()) {
             throw new NoSuchEntityException(__('Rule with specified ID "%1" not found.', $ruleId));
         }
         $this->rules[$ruleId] = $rule;
     }
     return $this->rules[$ruleId];
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing catalog rules:');
     $file = 'CatalogRule/catalog_rules.csv';
     $fileName = $this->fixtureHelper->getPath($file);
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
     foreach ($csvReader as $row) {
         /** @var \Magento\CatalogRule\Model\Resource\Rule\Collection $ruleCollection */
         $ruleCollection = $this->ruleCollectionFactory->create();
         $ruleCollection->addFilter('name', $row['name']);
         if ($ruleCollection->count() > 0) {
             continue;
         }
         $row['customer_group_ids'] = $this->getGroupIds();
         $row['website_ids'] = $this->getWebsiteIds();
         $row['conditions_serialized'] = $this->convertSerializedData($row['conditions_serialized']);
         $row['actions_serialized'] = $this->convertSerializedData($row['actions_serialized']);
         $ruleModel = $this->ruleFactory->create();
         $ruleModel->loadPost($row);
         $ruleModel->save();
         $this->logger->logInline('.');
     }
     $ruleJob = $this->jobFactory->create();
     $ruleJob->applyAll();
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing catalog rules:');
     $file = 'CatalogRule/catalog_rules.csv';
     $fileName = $this->fixtureHelper->getPath($file);
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
     foreach ($csvReader as $row) {
         $row['customer_group_ids'] = $this->getGroupIds();
         $row['website_ids'] = $this->getWebsiteIds();
         $row['conditions_serialized'] = $this->convertSerializedData($row['conditions_serialized']);
         $row['actions_serialized'] = $this->convertSerializedData($row['actions_serialized']);
         $ruleModel = $this->ruleFactory->create();
         $ruleModel->loadPost($row);
         $ruleModel->save();
         $this->logger->logInline('.');
     }
     $ruleJob = $this->jobFactory->create();
     $ruleJob->applyAll();
 }
Example #6
0
 /**
  * Check rules that contains affected attribute
  * If rules were found they will be set to inactive and notice will be add to admin session
  *
  * @param string $attributeCode
  * @return $this
  */
 protected function _checkCatalogRulesAvailability($attributeCode)
 {
     /* @var $collection Collection */
     $collection = $this->_ruleCollectionFactory->create()->addAttributeInConditionFilter($attributeCode);
     $disabledRulesCount = 0;
     foreach ($collection as $rule) {
         /* @var $rule Rule */
         $rule->setIsActive(0);
         /* @var $rule->getConditions() Combine */
         $this->_removeAttributeFromConditions($rule->getConditions(), $attributeCode);
         $rule->save();
         $disabledRulesCount++;
     }
     if ($disabledRulesCount) {
         $this->_ruleFactory->create()->applyAll();
         $this->messageManager->addWarning(__('%1 Catalog Price Rules based on "%2" attribute have been disabled.', $disabledRulesCount, $attributeCode));
     }
     return $this;
 }