Skip to content

Commit 57b525a

Browse files
authored
fix product export of configurable_variations for configurable products with multiple super attributes (#142) (#169)
1 parent 51a9c61 commit 57b525a

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,32 @@ public function prepareData($collection, $productIds)
6767
{
6868
$productCollection = clone $collection;
6969
$productCollection->addAttributeToFilter('entity_id', ['in' => $productIds])
70-
->addAttributeToFilter('type_id', ['eq' => ConfigurableProductType::TYPE_CODE]);
70+
->addAttributeToFilter('type_id', ['eq' => ConfigurableProductType::TYPE_CODE]);
7171

7272
// set global scope during export
7373
$this->storeManager->setCurrentStore(Store::DEFAULT_STORE_ID);
7474

7575
while ($product = $productCollection->fetchItem()) {
76-
$productAttributesOptions = $product->getTypeInstance()->getConfigurableOptions($product);
76+
/** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable $configurableInstance */
77+
$configurableInstance = $product->getTypeInstance();
78+
$productAttributesOptions = $configurableInstance->getConfigurableOptions($product);
7779
$this->configurableData[$product->getId()] = [];
7880
$variations = [];
7981
$variationsLabels = [];
8082

81-
foreach ($productAttributesOptions as $productAttributeOption) {
82-
foreach ($productAttributeOption as $optValues) {
83-
$variations[$optValues['sku']][] = $optValues['attribute_code'] . '=' . $optValues['option_title'];
83+
/** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute[] $superAttributes */
84+
$superAttributes = $configurableInstance->getUsedProductAttributes($product) ?? [];
85+
foreach ($superAttributes as $superAttribute) {
86+
$code = $superAttribute->getAttributeCode();
87+
$variationsLabels[$code] = $code . '=' . $superAttribute->getDefaultFrontendLabel();
88+
}
8489

85-
if (!empty($optValues['super_attribute_label'])) {
86-
$variationsLabels[$optValues['attribute_code']] = $optValues['attribute_code'] . '='
87-
. $optValues['super_attribute_label'];
88-
}
90+
/** @var \Magento\Catalog\Model\Product[] $childProducts */
91+
$childProducts = $configurableInstance->getUsedProducts($product) ?? [];
92+
foreach ($childProducts as $childProduct) {
93+
foreach ($superAttributes as $superAttribute) {
94+
$code = $superAttribute->getAttributeCode();
95+
$variations[$childProduct->getSku()][] = $code . '=' . $childProduct->getAttributeText($code);
8996
}
9097
}
9198

0 commit comments

Comments
 (0)