Esempio n. 1
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;
 }
Esempio n. 2
0
 public function testSaveData()
 {
     $associatedSku = 'sku_assoc';
     $productSku = 'productSku';
     $this->entityModel->expects($this->once())->method('getNewSku')->will($this->returnValue([$associatedSku => ['entity_id' => 1], $productSku => ['entity_id' => 2]]));
     $attributes = ['position' => ['id' => 0], 'qty' => ['id' => 0]];
     $this->links->expects($this->once())->method('getAttributes')->will($this->returnValue($attributes));
     $bunch = [['_associated_sku' => $associatedSku, 'sku' => $productSku, '_type' => 'grouped', '_associated_default_qty' => 4, '_associated_position' => 6]];
     $this->entityModel->expects($this->at(0))->method('getNextBunch')->will($this->returnValue($bunch));
     $this->entityModel->expects($this->at(1))->method('getNextBunch')->will($this->returnValue($bunch));
     $this->entityModel->expects($this->any())->method('isRowAllowedToImport')->will($this->returnValue(true));
     $this->entityModel->expects($this->any())->method('getRowScope')->will($this->returnValue(\Magento\CatalogImportExport\Model\Import\Product::SCOPE_DEFAULT));
     $this->links->expects($this->once())->method("saveLinksData");
     $this->grouped->saveData();
 }
Esempio n. 3
0
 /**
  * Test saveData() with store row scope
  */
 public function testSaveDataScopeStore()
 {
     $this->entityModel->expects($this->once())->method('getNewSku')->will($this->returnValue(['sku_assoc1' => ['entity_id' => 1], 'productSku' => ['entity_id' => 2, 'attr_set_code' => 'Default', 'type_id' => 'grouped']]));
     $this->entityModel->expects($this->once())->method('getOldSku')->will($this->returnValue(['sku_assoc2' => ['entity_id' => 3]]));
     $attributes = ['position' => ['id' => 0], 'qty' => ['id' => 0]];
     $this->links->expects($this->once())->method('getAttributes')->will($this->returnValue($attributes));
     $bunch = [['associated_skus' => 'sku_assoc1=1, sku_assoc2=2', 'sku' => 'productSku', 'product_type' => 'grouped']];
     $this->entityModel->expects($this->at(2))->method('getNextBunch')->will($this->returnValue($bunch));
     $this->entityModel->expects($this->any())->method('isRowAllowedToImport')->will($this->returnValue(true));
     $this->entityModel->expects($this->at(4))->method('getRowScope')->will($this->returnValue(\Magento\CatalogImportExport\Model\Import\Product::SCOPE_DEFAULT));
     $this->entityModel->expects($this->at(5))->method('getRowScope')->will($this->returnValue(\Magento\CatalogImportExport\Model\Import\Product::SCOPE_STORE));
     $this->links->expects($this->once())->method('saveLinksData');
     $this->grouped->saveData();
 }
Esempio n. 4
0
 /**
  * @param array $dbAttributes
  * @param array $returnedAttibutes
  *
  * @dataProvider attributesDataProvider
  */
 public function testGetAttributes($dbAttributes, $returnedAttibutes)
 {
     $this->processAttributeGetter($dbAttributes);
     $actualAttributes = $this->links->getAttributes();
     $this->assertEquals($returnedAttibutes, $actualAttributes);
 }