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
 /**
  * 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;
 }
Example #3
0
 /**
  * @param array $row
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 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;
 }