6
6
namespace Magento \ConfigurableImportExport \Model \Export ;
7
7
8
8
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 ;
10
12
use Magento \ImportExport \Model \Import ;
11
13
12
14
class RowCustomizer implements RowCustomizerInterface
@@ -19,51 +21,45 @@ class RowCustomizer implements RowCustomizerInterface
19
21
/**
20
22
* Prepare configurable data for export
21
23
*
22
- * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
24
+ * @param ProductCollection $collection
23
25
* @param int[] $productIds
24
26
* @return void
25
27
*/
26
28
public function prepareData ($ collection , $ productIds )
27
29
{
28
30
$ 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 ]);
36
33
37
34
while ($ product = $ productCollection ->fetchItem ()) {
38
35
$ productAttributesOptions = $ product ->getTypeInstance ()->getConfigurableOptions ($ product );
36
+ $ this ->configurableData [$ product ->getId ()] = [];
37
+ $ variations = [];
38
+ $ variationsLabels = [];
39
39
40
40
foreach ($ productAttributesOptions as $ productAttributeOption ) {
41
- $ this ->configurableData [$ product ->getId ()] = [];
42
- $ variations = [];
43
- $ variationsLabels = [];
44
-
45
41
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
+
48
44
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 ' ];
51
47
}
52
48
}
49
+ }
53
50
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 );
66
54
}
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
+ ];
67
63
}
68
64
}
69
65
0 commit comments