Skip to content

Commit 083147c

Browse files
committed
MAGETWO-71013: Export missing configurable variations when exporting more than one item
- Remove logic for dependent headers. Headers should be fixed. - Pass clean collection to row customizers to resolve conflict with pagination. - Remove unnecessary code in appendMultirowData method.
1 parent c8c6aaf commit 083147c

File tree

2 files changed

+45
-38
lines changed

2 files changed

+45
-38
lines changed

app/code/Magento/CatalogImportExport/Model/Export/Product.php

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,15 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
153153
/**
154154
* Items per page for collection limitation
155155
*
156-
* @var null
156+
* @var int|null
157157
*/
158158
protected $_itemsPerPage = null;
159159

160160
/**
161161
* Header columns for export file
162162
*
163163
* @var array
164+
* @deprecated
164165
*/
165166
protected $_headerColumns = [];
166167

@@ -234,17 +235,15 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
234235
protected $_fieldsMap = [
235236
'image' => 'base_image',
236237
'image_label' => "base_image_label",
237-
'image' => 'base_image',
238-
'image_label' => 'base_image_label',
239238
'thumbnail' => 'thumbnail_image',
240239
'thumbnail_label' => 'thumbnail_image_label',
241240
self::COL_MEDIA_IMAGE => 'additional_images',
242241
'_media_image_label' => 'additional_image_labels',
243-
Product::COL_STORE => 'store_view_code',
244-
Product::COL_ATTR_SET => 'attribute_set_code',
245-
Product::COL_TYPE => 'product_type',
246-
Product::COL_CATEGORY => 'categories',
247-
Product::COL_PRODUCT_WEBSITES => 'product_websites',
242+
self::COL_STORE => 'store_view_code',
243+
self::COL_ATTR_SET => 'attribute_set_code',
244+
self::COL_TYPE => 'product_type',
245+
self::COL_CATEGORY => 'categories',
246+
self::COL_PRODUCT_WEBSITES => 'product_websites',
248247
'status' => 'product_online',
249248
'news_from_date' => 'new_from_date',
250249
'news_to_date' => 'new_to_date',
@@ -691,7 +690,7 @@ protected function updateDataWithCategoryColumns(&$dataRow, &$rowCategories, $pr
691690
*/
692691
public function _getHeaderColumns()
693692
{
694-
return $this->_customHeadersMapping($this->_headerColumns);
693+
return $this->_customHeadersMapping($this->rowCustomizer->addHeaderColumns($this->_headerColumns));
695694
}
696695

697696
/**
@@ -700,13 +699,13 @@ public function _getHeaderColumns()
700699
* @param array $customOptionsData
701700
* @param array $stockItemRows
702701
* @return void
702+
* @deprecated Logic will be moved to _getHeaderColumns in future release
703+
*
704+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
703705
*/
704706
protected function setHeaderColumns($customOptionsData, $stockItemRows)
705707
{
706708
if (!$this->_headerColumns) {
707-
$customOptCols = [
708-
'custom_options',
709-
];
710709
$this->_headerColumns = array_merge(
711710
[
712711
self::COL_SKU,
@@ -719,21 +718,19 @@ protected function setHeaderColumns($customOptionsData, $stockItemRows)
719718
$this->_getExportMainAttrCodes(),
720719
[self::COL_ADDITIONAL_ATTRIBUTES],
721720
reset($stockItemRows) ? array_keys(end($stockItemRows)) : [],
722-
[],
723721
[
724722
'related_skus',
725723
'related_position',
726724
'crosssell_skus',
727725
'crosssell_position',
728726
'upsell_skus',
729-
'upsell_position'
730-
],
731-
['additional_images', 'additional_image_labels', 'hide_from_product_page']
727+
'upsell_position',
728+
'additional_images',
729+
'additional_image_labels',
730+
'hide_from_product_page',
731+
'custom_options'
732+
]
732733
);
733-
// have we merge custom options columns
734-
if ($customOptionsData) {
735-
$this->_headerColumns = array_merge($this->_headerColumns, $customOptCols);
736-
}
737734
}
738735
}
739736

@@ -892,10 +889,12 @@ protected function getExportData()
892889
$productIds = array_keys($rawData);
893890
$stockItemRows = $this->prepareCatalogInventory($productIds);
894891

895-
$this->rowCustomizer->prepareData($this->_getEntityCollection(), $productIds);
892+
$this->rowCustomizer->prepareData(
893+
$this->_prepareEntityCollection($this->_entityCollectionFactory->create()),
894+
$productIds
895+
);
896896

897897
$this->setHeaderColumns($multirawData['customOptionsData'], $stockItemRows);
898-
$this->_headerColumns = $this->rowCustomizer->addHeaderColumns($this->_headerColumns);
899898

900899
foreach ($rawData as $productId => $productData) {
901900
foreach ($productData as $storeId => $dataRow) {
@@ -1231,9 +1230,6 @@ private function appendMultirowData(&$dataRow, &$multiRawData)
12311230
return null;
12321231
} elseif ($storeId != Store::DEFAULT_STORE_ID) {
12331232
$dataRow[self::COL_STORE] = $this->_storeIdToCode[$storeId];
1234-
if (isset($productData[Store::DEFAULT_STORE_ID][self::COL_VISIBILITY])) {
1235-
$dataRow[self::COL_VISIBILITY] = $productData[Store::DEFAULT_STORE_ID][self::COL_VISIBILITY];
1236-
}
12371233
}
12381234
$dataRow[self::COL_SKU] = $sku;
12391235
return $dataRow;

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,29 @@
1313

1414
class RowCustomizer implements RowCustomizerInterface
1515
{
16+
/**
17+
* Header column for Configurable Product variations
18+
*/
19+
const CONFIGURABLE_VARIATIONS_COLUMN = 'configurable_variations';
20+
21+
/**
22+
* Header column for Configurable Product variation labels
23+
*/
24+
const CONFIGURABLE_VARIATIONS_LABELS_COLUMN = 'configurable_variation_labels';
25+
1626
/**
1727
* @var array
1828
*/
1929
protected $configurableData = [];
2030

31+
/**
32+
* @var string[]
33+
*/
34+
private $configurableColumns = [
35+
self::CONFIGURABLE_VARIATIONS_COLUMN,
36+
self::CONFIGURABLE_VARIATIONS_LABELS_COLUMN
37+
];
38+
2139
/**
2240
* Prepare configurable data for export
2341
*
@@ -54,8 +72,11 @@ public function prepareData($collection, $productIds)
5472
}
5573

5674
$this->configurableData[$product->getId()] = [
57-
'configurable_variations' => implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $variations),
58-
'configurable_variation_labels' => implode(
75+
self::CONFIGURABLE_VARIATIONS_COLUMN => implode(
76+
ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR,
77+
$variations
78+
),
79+
self::CONFIGURABLE_VARIATIONS_LABELS_COLUMN => implode(
5980
Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR,
6081
$variationsLabels
6182
)
@@ -71,17 +92,7 @@ public function prepareData($collection, $productIds)
7192
*/
7293
public function addHeaderColumns($columns)
7394
{
74-
// have we merge configurable products data
75-
if (!empty($this->configurableData)) {
76-
$columns = array_merge(
77-
$columns,
78-
[
79-
'configurable_variations',
80-
'configurable_variation_labels',
81-
]
82-
);
83-
}
84-
return $columns;
95+
return array_merge($columns, $this->configurableColumns);
8596
}
8697

8798
/**

0 commit comments

Comments
 (0)