예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log("Installing {$this->productType} products:");
     $product = $this->productFactory->create();
     foreach ($this->fixtures as $file) {
         /** @var \Magento\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('.');
         }
     }
 }
예제 #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;
 }
예제 #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;
 }
 /**
  * @param array $configurableAttributes
  * @return array
  */
 protected function getProductAttributes($configurableAttributes)
 {
     $attributesData = [];
     foreach ($configurableAttributes as $attributeCode => $value) {
         $attribute = $this->eavConfig->getAttribute('catalog_product', $attributeCode);
         if (!$attribute->getId()) {
             continue;
         }
         $options = $this->productConverter->getAttributeOptions($attribute->getAttributeCode());
         $attributeOption = $options->getItemByColumnValue('value', $value);
         $attributeId = $attributeOption->getDataByKey('attribute_id');
         $attributesData[$attributeId] = $attributeOption->getDataByKey('option_id');
     }
     return $attributesData;
 }
 /**
  * @param string $urlAttributes
  * @return string
  */
 protected function getUrlFilter($urlAttributes)
 {
     $separatedAttributes = $this->getArrayValue($urlAttributes, ';');
     $urlFilter = null;
     foreach ($separatedAttributes as $attributeNumber => $attributeValue) {
         $attributeData = $this->getArrayValue($attributeValue, '=');
         $attributeOptions = $this->productConverter->getAttributeOptions($attributeData[0]);
         $attributeValue = $attributeOptions->getItemByColumnValue('value', $attributeData[1]);
         if ($attributeNumber == 0) {
             $urlFilter = $attributeData[0] . '=' . $attributeValue->getId();
             continue;
         }
         $urlFilter .= '&' . $attributeData[0] . '=' . $attributeValue->getId();
     }
     return $urlFilter;
 }