magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

Grouped product import fails for non-default stores #6184

Closed ndsina closed 7 years ago

ndsina commented 8 years ago

Steps to reproduce

  1. Go to Admin -> System -> Import
  2. Select import product
  3. Import CSV file with grouped products

    Expected result

  1. Import successfully done

    Actual result

  1. Import fails with the following error: Undefined index 'attr_set_code' in vendor/magento/module-grouped-import-export/Model/Import/Product/Type/Grouped.php

As a variant of fix could be used this code in the vendor/magento/module-grouped-import-export/Model/Import/Product/Type/Grouped.php file:

//$scope = $this->_entityModel->getRowScope($rowData);
//if (Product::SCOPE_DEFAULT == $scope || empty($productData)) {
$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'];
//}
sshymko commented 8 years ago

Preconditions:

victor-v-rad commented 8 years ago

could not reproduce. Please share your import csv file. It might help

lucacanella commented 8 years ago

I cannot share csv file but I'm experiencing the same bug:

  1. I imported a file with only grouped products to the default store: import gone well;
  2. I tried to import the same file changing only the 'store_view_code' column: check data succeeded but import failed with following error.

"General system exception happened Additional data: Notice: Undefined index: attr_set_code in ...vendor/magento/module-grouped-import-export/Model/Import/Product/Type/Grouped.php on line 105"

Storeview code is correct (and worked well for other - non grouped - products). Products included in each group have been correctly imported in referred storeview.

I think this issue is also related: https://github.com/magento/magento2/issues/5668

imran-herrmann commented 2 years ago

Got the same bug in Magento2.4.2-p2. Fixed it as described in the start of this thread with a composer patch:

diff --git a/application/vendor/magento/module-grouped-import-export/Model/Import/Product/Type/Grouped.php b/application/vendor/magento/module-grouped-import-export/Model/Import/Product/Type/Grouped.php
--- a/Model/Import/Product/Type/Grouped.php
+++ b/Model/Import/Product/Type/Grouped.php (date 1645173694713)
@@ -97,14 +97,10 @@
                     } else {
                         continue;
                     }
-                    $scope = $this->_entityModel->getRowScope($rowData);
-                    if (Product::SCOPE_DEFAULT == $scope) {
-                        $productData = $newSku[strtolower($rowData[Product::COL_SKU])];
-                    } else {
-                        $colAttrSet = Product::COL_ATTR_SET;
-                        $rowData[$colAttrSet] = $productData['attr_set_code'];
-                        $rowData[Product::COL_TYPE] = $productData['type_id'];
-                    }
+                    $productData = $newSku[strtolower($rowData[Product::COL_SKU])];
+                    $colAttrSet = Product::COL_ATTR_SET;
+                    $rowData[$colAttrSet] = $productData['attr_set_code'];
+                    $rowData[Product::COL_TYPE] = $productData['type_id'];
                     $productId = $productData[$this->getProductEntityLinkField()];

                     $linksData['product_ids'][$productId] = true;
Bhavik-kumar commented 7 months ago

Issue is able to reproduce on specific area for different website. Group product create and set with for different website, not for main website @magento-engcom-team

akarso commented 1 month ago

M2 2.4.7-p2

\Magento\GroupedImportExport\Model\Import\Product\Type\Grouped::saveData

Here we have an error in line 135 ('attr_set_code' index does not exist). Looking at the app flow, $productData is set at the very beginning to [] and then, if certain conditions are met, this happens:

$rowData[$colAttrSet] = $productData['attr_set_code']; So this cannot work.

Prerequisites:

Simple products have to exist. If trying to import to empty db it actually works, because it hits 'continue' in line 127 Skus must be written like that: 000016198=1 Probably also error reporting level must be set to high (index not existing is actually a warning) Sku like 000016198=1 is being split here:

\Magento\GroupedImportExport\Model\Import\Product\Type\Grouped::normalizeSkusAndQty for a sku=>qty pair. If there is no $associatedSkusAndQtyPairs in line 112 then again script doesn't hit the loop in which it breaks.