/** * {@inheritdoc} */ public function run() { $this->logger->log('Installing related product rules:'); $this->postInstaller->removeSetupResourceType('Magento\\SampleData\\Module\\Catalog\\Setup\\ProductLink'); $entityFileAssociation = [\Magento\TargetRule\Model\Rule::RELATED_PRODUCTS => 'related', \Magento\TargetRule\Model\Rule::UP_SELLS => 'upsell', \Magento\TargetRule\Model\Rule::CROSS_SELLS => 'crosssell']; foreach ($entityFileAssociation as $linkTypeId => $linkType) { $fileName = 'TargetRule/' . $linkType . '.csv'; $fileName = $this->fixtureHelper->getPath($fileName); if (!$fileName) { continue; } /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */ $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']); foreach ($csvReader as $row) { /** @var \Magento\TargetRule\Model\Rule $rule */ $rule = $this->ruleFactory->create(); if ($rule->getResourceCollection()->addFilter('name', $row['name'])->getSize() > 0) { continue; } $sourceCategory = $this->getConditionFromCategory(array_filter(explode("\n", $row['source_category'])), 'Rule'); $targetCategory = $this->getConditionFromCategory(array_filter(explode("\n", $row['target_category'])), 'Actions'); if (!$sourceCategory || !$targetCategory) { continue; } $targetCategory['value_type'] = TargetRuleActionAttributes::VALUE_TYPE_CONSTANT; $ruleConditions = $this->createConditions($sourceCategory, $targetCategory); $rule->setName($row['name'])->setApplyTo($linkTypeId)->setIsActive(1)->setSortOrder(0)->setPositionsLimit(empty($row['limit']) ? 0 : $row['limit']); $rule->loadPost($ruleConditions); $rule->save(); $this->logger->logInline('.'); } } }
/** * {@inheritdoc} */ public function run() { $this->postInstaller->removeSetupResourceType('Magento\\SampleData\\Module\\Wishlist\\Setup\\Wishlist'); $this->postInstaller->addSetupResource($this->wishlistSetup); }