Example #1
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log("Installing {$this->productType} products:");
     $product = $this->productFactory->create();
     foreach ($this->fixtures as $file) {
         /** @var \Magento\Tools\SampleData\Helper\Csv\Reader $csvReader */
         $fileName = $this->fixtureHelper->getPath($file);
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
         foreach ($csvReader as $row) {
             $attributeSetId = $this->catalogConfig->getAttributeSetId(4, $row['attribute_set']);
             $this->converter->setAttributeSetId($attributeSetId);
             $data = $this->converter->convertRow($row);
             $product->unsetData();
             $product->setData($data);
             $product->setTypeId($this->productType)->setAttributeSetId($attributeSetId)->setWebsiteIds([$this->storeManager->getWebsiteId()])->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)->setStockData(['is_in_stock' => 1, 'manage_stock' => 0])->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
             if (empty($data['visibility'])) {
                 $product->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH);
             }
             $this->prepareProduct($product, $data);
             $product->save();
             $this->gallery->install($product);
             $this->logger->logInline('.');
         }
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function install($product)
 {
     parent::install($product);
     foreach ($product->getAssociatedProductIds() as $id) {
         $product = $this->productFactory->create()->load($id);
         parent::install($product);
     }
 }
Example #3
0
 /**
  * @param \Magento\Catalog\Model\ProductFactory $productFactory
  * @param \Magento\Catalog\Model\Config $catalogConfig
  * @param Product\Converter $converter
  * @param FixtureHelper $fixtureHelper
  * @param CsvReaderFactory $csvReaderFactory
  * @param Gallery $gallery
  * @param \Magento\Tools\SampleData\Logger $logger
  * @param \Magento\Tools\SampleData\Helper\StoreManager $storeManager
  * @param array $fixtures
  * @codingStandardsIgnoreStart
  */
 public function __construct(\Magento\Catalog\Model\ProductFactory $productFactory, \Magento\Catalog\Model\Config $catalogConfig, Product\Converter $converter, FixtureHelper $fixtureHelper, CsvReaderFactory $csvReaderFactory, Gallery $gallery, \Magento\Tools\SampleData\Logger $logger, \Magento\Tools\SampleData\Helper\StoreManager $storeManager, $fixtures = ['GroupedProduct/yoga_grouped.csv'])
 {
     $gallery->setFixtures(['GroupedProduct/images_yoga_grouped.csv']);
     parent::__construct($productFactory, $catalogConfig, $converter, $fixtureHelper, $csvReaderFactory, $gallery, $logger, $storeManager, $fixtures);
 }