/** * Save product type specific data. * * @return \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function saveData() { $newSku = $this->_entityModel->getNewSku(); $oldSku = $this->_entityModel->getOldSku(); $attributes = $this->links->getAttributes(); $productData = []; while ($bunch = $this->_entityModel->getNextBunch()) { $linksData = ['product_ids' => [], 'attr_product_ids' => [], 'position' => [], 'qty' => [], 'relation' => []]; foreach ($bunch as $rowNum => $rowData) { $associatedSkusQty = isset($rowData['associated_skus']) ? $rowData['associated_skus'] : null; if (!$this->_entityModel->isRowAllowedToImport($rowData, $rowNum) || empty($associatedSkusQty)) { continue; } $associatedSkusAndQtyPairs = explode(Product::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $associatedSkusQty); $position = 0; foreach ($associatedSkusAndQtyPairs as $associatedSkuAndQty) { ++$position; $associatedSkuAndQty = explode(self::SKU_QTY_DELIMITER, $associatedSkuAndQty); $associatedSku = isset($associatedSkuAndQty[0]) ? trim($associatedSkuAndQty[0]) : null; if (isset($newSku[$associatedSku])) { $linkedProductId = $newSku[$associatedSku]['entity_id']; } elseif (isset($oldSku[$associatedSku])) { $linkedProductId = $oldSku[$associatedSku]['entity_id']; } else { continue; } $scope = $this->_entityModel->getRowScope($rowData); if (Product::SCOPE_DEFAULT == $scope) { $productData = $newSku[$rowData[Product::COL_SKU]]; } else { $colAttrSet = Product::COL_ATTR_SET; $rowData[$colAttrSet] = $productData['attr_set_code']; $rowData[Product::COL_TYPE] = $productData['type_id']; } $productId = $productData['entity_id']; if ($this->_type != $rowData[Product::COL_TYPE]) { continue; } $linksData['product_ids'][$productId] = true; $linksData['relation'][] = ['parent_id' => $productId, 'child_id' => $linkedProductId]; $qty = empty($associatedSkuAndQty[1]) ? 0 : trim($associatedSkuAndQty[1]); $linksData['attr_product_ids'][$productId] = true; $linksData['position']["{$productId} {$linkedProductId}"] = ['product_link_attribute_id' => $attributes['position']['id'], 'value' => $position]; if ($qty) { $linksData['attr_product_ids'][$productId] = true; $linksData['qty']["{$productId} {$linkedProductId}"] = ['product_link_attribute_id' => $attributes['qty']['id'], 'value' => $qty]; } } } $this->links->saveLinksData($linksData); } return $this; }
/** * @param array $dbAttributes * @param array $returnedAttibutes * * @dataProvider attributesDataProvider */ public function testGetAttributes($dbAttributes, $returnedAttibutes) { $this->processAttributeGetter($dbAttributes); $actualAttributes = $this->links->getAttributes(); $this->assertEquals($returnedAttibutes, $actualAttributes); }