/** * Create product model from imported data for URL rewrite purposes. * * @param array $rowData * * @return ImportExport * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _populateForUrlGeneration($rowData) { $newSku = $this->import->getNewSku($rowData[ImportProduct::COL_SKU]); if (empty($newSku) || !isset($newSku['entity_id'])) { return null; } $rowData['entity_id'] = $newSku['entity_id']; $product = $this->catalogProductFactory->create(); $product->setId($rowData['entity_id']); foreach ($this->vitalForGenerationFields as $field) { if (isset($rowData[$field])) { $product->setData($field, $rowData[$field]); } } $this->categoryCache[$rowData['entity_id']] = $this->import->getProductCategories($rowData['sku']); $this->websiteCache[$rowData['entity_id']] = $this->import->getProductWebsites($rowData['sku']); foreach ($this->websiteCache[$rowData['entity_id']] as $websiteId) { if (!isset($this->websitesToStoreIds[$websiteId])) { $this->websitesToStoreIds[$websiteId] = $this->storeManager->getWebsite($websiteId)->getStoreIds(); } } if (!empty($rowData[ImportProduct::COL_STORE]) && ($storeId = $this->import->getStoreIdByCode($rowData[ImportProduct::COL_STORE]))) { $product->setStoreId($storeId); } if ($this->isGlobalScope($product->getStoreId())) { $this->populateGlobalProduct($product); } else { $this->addProductToImport($product, $product->getStoreId()); } return $this; }
/** * @param \Magento\Catalog\Model\Product $product * @param array $rowData * @return void */ protected function setStoreToProduct(\Magento\Catalog\Model\Product $product, array $rowData) { if (!empty($rowData[ImportProduct::COL_STORE]) && ($storeId = $this->import->getStoreIdByCode($rowData[ImportProduct::COL_STORE]))) { $product->setStoreId($storeId); } elseif (!$product->hasData(\Magento\Catalog\Model\Product::STORE_ID)) { $product->setStoreId(Store::DEFAULT_STORE_ID); } }
/** * Cover getStoreIdByCode(). * * @dataProvider getStoreIdByCodeDataProvider */ public function testGetStoreIdByCode($storeCode, $expectedResult) { $this->storeResolver->expects($this->any())->method('getStoreCodeToId')->willReturn('getStoreCodeToId value'); $actualResult = $this->importProduct->getStoreIdByCode($storeCode); $this->assertEquals($expectedResult, $actualResult); }