Exemplo n.º 1
0
 /**
  * @param array $linksData
  *
  * @dataProvider linksDataProvider
  */
 public function testSaveLinksDataWithProductsAttrs($linksData)
 {
     $linksData['attr_product_ids'] = [12 => true, 16 => true];
     $linksData['position'] = [4 => 6];
     $linksData['qty'] = [9 => 3];
     $this->processBehaviorGetter('append');
     $select = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $this->connection->expects($this->any())->method('select')->will($this->returnValue($select));
     $select->expects($this->any())->method('from')->will($this->returnSelf());
     $select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->connection->expects($this->once())->method('fetchAll')->with($select)->will($this->returnValue([]));
     $this->connection->expects($this->once())->method('fetchPairs')->with($select)->will($this->returnValue([]));
     $this->connection->expects($this->exactly(4))->method('insertOnDuplicate');
     $this->links->saveLinksData($linksData);
 }
Exemplo n.º 2
0
 /**
  * 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;
 }