/**
  * 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;
 }
Example #2
0
 /**
  * Cover getNewSku().
  */
 public function testGetNewSku()
 {
     $expectedSku = 'value';
     $expectedResult = 'result value';
     $this->skuProcessor->expects($this->any())->method('getNewSku')->with($expectedSku)->willReturn($expectedResult);
     $actualResult = $this->importProduct->getNewSku($expectedSku);
     $this->assertEquals($expectedResult, $actualResult);
 }