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
14
+ /**
15
+ * Exporting configurable products
16
+ */
12
17
class RowCustomizer implements RowCustomizerInterface
13
18
{
14
19
/**
@@ -19,51 +24,45 @@ class RowCustomizer implements RowCustomizerInterface
19
24
/**
20
25
* Prepare configurable data for export
21
26
*
22
- * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
27
+ * @param ProductCollection $collection
23
28
* @param int[] $productIds
24
29
* @return void
25
30
*/
26
31
public function prepareData ($ collection , $ productIds )
27
32
{
28
33
$ 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 ]);
36
36
37
37
while ($ product = $ productCollection ->fetchItem ()) {
38
38
$ productAttributesOptions = $ product ->getTypeInstance ()->getConfigurableOptions ($ product );
39
+ $ this ->configurableData [$ product ->getId ()] = [];
40
+ $ variations = [];
41
+ $ variationsLabels = [];
39
42
40
43
foreach ($ productAttributesOptions as $ productAttributeOption ) {
41
- $ this ->configurableData [$ product ->getId ()] = [];
42
- $ variations = [];
43
- $ variationsLabels = [];
44
-
45
44
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
+
48
47
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 ' ];
51
50
}
52
51
}
52
+ }
53
53
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 );
66
57
}
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
+ ];
67
66
}
68
67
}
69
68
0 commit comments