Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function install(array $fixtures)
 {
     $attribute = $this->eavConfig->getAttribute('catalog_product', 'sku');
     if ($attribute->getIsUsedForPromoRules() == 0) {
         $attribute->setIsUsedForPromoRules('1')->save();
     }
     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;
             /** @var \Magento\SalesRule\Model\ResourceModel\Rule\Collection $ruleCollection */
             $ruleCollection = $this->ruleCollectionFactory->create();
             $ruleCollection->addFilter('name', $row['name']);
             if ($ruleCollection->count() > 0) {
                 continue;
             }
             $row['customer_group_ids'] = $this->catalogRule->getGroupIds();
             $row['website_ids'] = $this->catalogRule->getWebsiteIds();
             $row['conditions_serialized'] = $this->catalogRule->convertSerializedData($row['conditions_serialized']);
             $row['actions_serialized'] = $this->catalogRule->convertSerializedData($row['actions_serialized']);
             /** @var \Magento\SalesRule\Model\Rule $rule */
             $rule = $this->ruleFactory->create();
             $rule->loadPost($row);
             $rule->save();
         }
     }
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function install()
 {
     $this->rule->install(['Magento_CatalogRuleSampleData::fixtures/catalog_rules.csv']);
 }