Ejemplo n.º 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();
 }
 /**
  * {@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();
 }
Ejemplo n.º 3
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();
 }