@@ -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