Skip to content

Commit f65375d

Browse files
committed
MAGETWO-58299: [Github] Imported configurable products with multiple super attributes do not retain super attribute ordering #6079
1 parent bdd93e2 commit f65375d

File tree

1 file changed

+25
-30
lines changed

1 file changed

+25
-30
lines changed

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

Lines changed: 25 additions & 30 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,44 @@ 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'];
48-
if (!empty($optValues['super_attribute_label'])) {
49-
$variationsLabels[$optValues['attribute_code']] =
50-
$optValues['attribute_code'] . '=' . $optValues['super_attribute_label'];
51-
}
52-
}
42+
$variations[$optValues['sku']][] = $optValues['attribute_code'] . '=' . $optValues['option_title'];
5343

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);
44+
if (isset($optValues['super_attribute_label'])) {
45+
$variationsLabels[$optValues['attribute_code']] = $optValues['attribute_code'] . '='
46+
. $optValues['super_attribute_label'];
47+
}
5848
}
59-
$variations = implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $variations);
60-
$variationsLabels = implode(Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $variationsLabels);
49+
}
6150

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+
];
6762
}
6863
}
6964

0 commit comments

Comments
 (0)