Skip to content

Commit 9536d0e

Browse files
authored
Merge pull request #800 from magento-tango/MAGETWO-58299
Bug fixes: * MAGETWO-58299: [Github] Imported configurable products with multiple super attributes do not retain super attribute ordering #6079
2 parents 06dd04b + 285978a commit 9536d0e

File tree

3 files changed

+185
-191
lines changed

3 files changed

+185
-191
lines changed

app/code/Magento/ConfigurableImportExport/Model/Export/RowCustomizer.php

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
namespace Magento\ConfigurableImportExport\Model\Export;
77

88
use Magento\CatalogImportExport\Model\Export\RowCustomizerInterface;
9-
use \Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
9+
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
10+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableProductType;
11+
use Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
1012
use Magento\ImportExport\Model\Import;
1113

1214
class RowCustomizer implements RowCustomizerInterface
@@ -19,51 +21,45 @@ class RowCustomizer implements RowCustomizerInterface
1921
/**
2022
* Prepare configurable data for export
2123
*
22-
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
24+
* @param ProductCollection $collection
2325
* @param int[] $productIds
2426
* @return void
2527
*/
2628
public function prepareData($collection, $productIds)
2729
{
2830
$productCollection = clone $collection;
29-
$productCollection->addAttributeToFilter(
30-
'entity_id',
31-
['in' => $productIds]
32-
)->addAttributeToFilter(
33-
'type_id',
34-
['eq' => \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE]
35-
);
31+
$productCollection->addAttributeToFilter('entity_id', ['in' => $productIds])
32+
->addAttributeToFilter('type_id', ['eq' => ConfigurableProductType::TYPE_CODE]);
3633

3734
while ($product = $productCollection->fetchItem()) {
3835
$productAttributesOptions = $product->getTypeInstance()->getConfigurableOptions($product);
36+
$this->configurableData[$product->getId()] = [];
37+
$variations = [];
38+
$variationsLabels = [];
3939

4040
foreach ($productAttributesOptions as $productAttributeOption) {
41-
$this->configurableData[$product->getId()] = [];
42-
$variations = [];
43-
$variationsLabels = [];
44-
4541
foreach ($productAttributeOption as $optValues) {
46-
$variations[$optValues['sku']][] =
47-
$optValues['attribute_code'] . '=' . $optValues['option_title'];
42+
$variations[$optValues['sku']][] = $optValues['attribute_code'] . '=' . $optValues['option_title'];
43+
4844
if (!empty($optValues['super_attribute_label'])) {
49-
$variationsLabels[$optValues['attribute_code']] =
50-
$optValues['attribute_code'] . '=' . $optValues['super_attribute_label'];
45+
$variationsLabels[$optValues['attribute_code']] = $optValues['attribute_code'] . '='
46+
. $optValues['super_attribute_label'];
5147
}
5248
}
49+
}
5350

54-
foreach ($variations as $sku => $values) {
55-
$variations[$sku] =
56-
'sku=' . $sku . Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR
57-
. implode(Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $values);
58-
}
59-
$variations = implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $variations);
60-
$variationsLabels = implode(Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $variationsLabels);
61-
62-
$this->configurableData[$product->getId()] = [
63-
'configurable_variations' => $variations,
64-
'configurable_variation_labels' => $variationsLabels,
65-
];
51+
foreach ($variations as $sku => $values) {
52+
$variations[$sku] = 'sku=' . $sku . Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR
53+
. implode(Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $values);
6654
}
55+
56+
$this->configurableData[$product->getId()] = [
57+
'configurable_variations' => implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $variations),
58+
'configurable_variation_labels' => implode(
59+
Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR,
60+
$variationsLabels
61+
)
62+
];
6763
}
6864
}
6965

app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,15 +498,18 @@ protected function _parseVariations($rowData)
498498
}
499499

500500
if (!empty($fieldAndValuePairs['sku'])) {
501+
$position = 0;
501502
$additionalRow['_super_products_sku'] = $fieldAndValuePairs['sku'];
502503
unset($fieldAndValuePairs['sku']);
503504
$additionalRow['display'] = isset($fieldAndValuePairs['display']) ? $fieldAndValuePairs['display'] : 1;
504505
unset($fieldAndValuePairs['display']);
505506
foreach ($fieldAndValuePairs as $attrCode => $attrValue) {
506507
$additionalRow['_super_attribute_code'] = $attrCode;
507508
$additionalRow['_super_attribute_option'] = $attrValue;
509+
$additionalRow['_super_attribute_position'] = $position;
508510
$additionalRows[] = $additionalRow;
509511
$additionalRow = [];
512+
$position += 1;
510513
}
511514
}
512515
}
@@ -712,7 +715,7 @@ protected function _collectSuperDataLabels($data, $productSuperAttrId, $productI
712715
$attrParams = $this->_superAttributes[$data['_super_attribute_code']];
713716
$this->_superAttributesData['attributes'][$productId][$attrParams['id']] = [
714717
'product_super_attribute_id' => $productSuperAttrId,
715-
'position' => 0,
718+
'position' => $data['_super_attribute_position'],
716719
];
717720
$label = isset($variationLabels[$data['_super_attribute_code']])
718721
? $variationLabels[$data['_super_attribute_code']]

0 commit comments

Comments
 (0)