/** * @param array $productFixtures * @param array $galleryFixtures * @throws \Exception */ public function install(array $productFixtures, array $galleryFixtures) { $this->eavConfig->clear(); $this->setGalleryFixtures($galleryFixtures); $product = $this->productFactory->create(); foreach ($productFixtures 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; $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->getDefaultStoreView()->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->installGallery($product); } } }
/** * Convert CSV format row to array * * @param array $row * @return array */ public function convertRow($row) { $data = parent::convertRow($row); if (!empty($row['bundle_options'])) { $bundleData = $this->convertBundleOptions($row['bundle_options']); $data = array_merge($data, $bundleData); } return $data; }
/** * @param array $row * @return array */ public function convertRow($row) { $data = parent::convertRow($row); if (!empty($data['configurable_attributes_data'])) { $data['configurable_attributes_data'] = $this->convertAttributesData($data['configurable_attributes_data']); if (!empty($data['associated_product_ids'])) { $data['associated_product_ids'] = $this->convertSkuToIds($this->getArrayValue($data['associated_product_ids'])); } else { $data['variations_matrix'] = $this->getVariationsMatrix($data); } $data['new_variations_attribute_set_id'] = $this->getAttributeSetId(); } return $data; }