/** * {@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('.'); } } }
/** * {@inheritdoc} */ public function install($product) { parent::install($product); foreach ($product->getAssociatedProductIds() as $id) { $product = $this->productFactory->create()->load($id); parent::install($product); } }