Skip to content

Commit 20e1a7c

Browse files
committed
MAGETWO-63590: [Backport] - [Github] Imported configurable products with multiple super attributes do not retain super attribute ordering #6079 - for 2.0
1 parent 54d4e70 commit 20e1a7c

File tree

3 files changed

+192
-194
lines changed

3 files changed

+192
-194
lines changed

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

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
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

14+
/**
15+
* Exporting configurable products
16+
*/
1217
class RowCustomizer implements RowCustomizerInterface
1318
{
1419
/**
@@ -19,51 +24,45 @@ class RowCustomizer implements RowCustomizerInterface
1924
/**
2025
* Prepare configurable data for export
2126
*
22-
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
27+
* @param ProductCollection $collection
2328
* @param int[] $productIds
2429
* @return void
2530
*/
2631
public function prepareData($collection, $productIds)
2732
{
2833
$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-
);
34+
$productCollection->addAttributeToFilter('entity_id', ['in' => $productIds])
35+
->addAttributeToFilter('type_id', ['eq' => ConfigurableProductType::TYPE_CODE]);
3636

3737
while ($product = $productCollection->fetchItem()) {
3838
$productAttributesOptions = $product->getTypeInstance()->getConfigurableOptions($product);
39+
$this->configurableData[$product->getId()] = [];
40+
$variations = [];
41+
$variationsLabels = [];
3942

4043
foreach ($productAttributesOptions as $productAttributeOption) {
41-
$this->configurableData[$product->getId()] = [];
42-
$variations = [];
43-
$variationsLabels = [];
44-
4544
foreach ($productAttributeOption as $optValues) {
46-
$variations[$optValues['sku']][] =
47-
$optValues['attribute_code'] . '=' . $optValues['option_title'];
45+
$variations[$optValues['sku']][] = $optValues['attribute_code'] . '=' . $optValues['option_title'];
46+
4847
if (!empty($optValues['super_attribute_label'])) {
49-
$variationsLabels[$optValues['attribute_code']] =
50-
$optValues['attribute_code'] . '=' . $optValues['super_attribute_label'];
48+
$variationsLabels[$optValues['attribute_code']] = $optValues['attribute_code'] . '='
49+
. $optValues['super_attribute_label'];
5150
}
5251
}
52+
}
5353

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-
];
54+
foreach ($variations as $sku => $values) {
55+
$variations[$sku] = 'sku=' . $sku . Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR
56+
. implode(Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $values);
6657
}
58+
59+
$this->configurableData[$product->getId()] = [
60+
'configurable_variations' => implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $variations),
61+
'configurable_variation_labels' => implode(
62+
Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR,
63+
$variationsLabels
64+
)
65+
];
6766
}
6867
}
6968

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
/**
1616
* Importing configurable products
17-
* @package Magento\ConfigurableImportExport\Model\Import\Product\Type
1817
* @SuppressWarnings(PHPMD.TooManyFields)
1918
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2019
*/
@@ -479,15 +478,18 @@ protected function _parseVariations($rowData)
479478
}
480479

481480
if (!empty($fieldAndValuePairs['sku'])) {
481+
$position = 0;
482482
$additionalRow['_super_products_sku'] = $fieldAndValuePairs['sku'];
483483
unset($fieldAndValuePairs['sku']);
484484
$additionalRow['display'] = isset($fieldAndValuePairs['display']) ? $fieldAndValuePairs['display'] : 1;
485485
unset($fieldAndValuePairs['display']);
486486
foreach ($fieldAndValuePairs as $attrCode => $attrValue) {
487487
$additionalRow['_super_attribute_code'] = $attrCode;
488488
$additionalRow['_super_attribute_option'] = $attrValue;
489+
$additionalRow['_super_attribute_position'] = $position;
489490
$additionalRows[] = $additionalRow;
490491
$additionalRow = [];
492+
$position += 1;
491493
}
492494
}
493495
}
@@ -690,7 +692,7 @@ protected function _collectSuperDataLabels($data, $productSuperAttrId, $productI
690692
$attrParams = $this->_superAttributes[$data['_super_attribute_code']];
691693
$this->_superAttributesData['attributes'][$productId][$attrParams['id']] = [
692694
'product_super_attribute_id' => $productSuperAttrId,
693-
'position' => 0,
695+
'position' => $data['_super_attribute_position'],
694696
];
695697
$label = isset($variationLabels[$data['_super_attribute_code']])
696698
? $variationLabels[$data['_super_attribute_code']]

0 commit comments

Comments
 (0)