/**
  * {@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();
 }
Esempio n. 2
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 RuleCollectionFactory */
     $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->ruleProductProcessor->markIndexerAsInvalid();
         $this->messageManager->addWarning(__('You disabled %1 Catalog Price Rules based on "%2" attribute.', $disabledRulesCount, $attributeCode));
     }
     return $this;
 }
Esempio n. 3
0
 /**
  * Create catalog rule relations for imported products
  *
  * @param EventObserver $observer
  * @return void
  */
 public function createCatalogRulesRelations(EventObserver $observer)
 {
     $adapter = $observer->getEvent()->getAdapter();
     $affectedEntityIds = $adapter->getAffectedEntityIds();
     if (empty($affectedEntityIds)) {
         return;
     }
     $rules = $this->_ruleCollectionFactory->create()->addFieldToFilter('is_active', 1);
     foreach ($rules as $rule) {
         $rule->setProductsFilter($affectedEntityIds);
         $this->_resourceRule->updateRuleProductData($rule);
     }
 }
Esempio n. 4
0
 /**
  * Get active rules
  *
  * @return array
  */
 protected function getAllRules()
 {
     return $this->ruleCollectionFactory->create();
 }