Skip to content

Commit db570ab

Browse files
committed
Merge remote-tracking branch 'tango/MC-19661-2' into Chaika-PR-2019-09-20
2 parents 5860041 + 8632e6d commit db570ab

File tree

8 files changed

+129
-35
lines changed

8 files changed

+129
-35
lines changed

app/code/Magento/AdvancedPricingImportExport/Model/Export/AdvancedPricing.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
*/
66
namespace Magento\AdvancedPricingImportExport\Model\Export;
77

8-
use Magento\ImportExport\Model\Export;
9-
use Magento\Store\Model\Store;
10-
use Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
118
use Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing as ImportAdvancedPricing;
129
use Magento\Catalog\Model\Product as CatalogProduct;
10+
use Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
11+
use Magento\ImportExport\Model\Export;
12+
use Magento\Store\Model\Store;
1313

1414
/**
1515
* Export Advanced Pricing
@@ -150,6 +150,8 @@ public function __construct(
150150
}
151151

152152
/**
153+
* Init type models
154+
*
153155
* @return $this
154156
* @throws \Magento\Framework\Exception\LocalizedException
155157
*/
@@ -172,7 +174,9 @@ protected function initTypeModels()
172174
}
173175
if ($model->isSuitable()) {
174176
$this->_productTypeModels[$productTypeName] = $model;
177+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
175178
$this->_disabledAttrs = array_merge($this->_disabledAttrs, $model->getDisabledAttrs());
179+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
176180
$this->_indexValueAttributes = array_merge(
177181
$this->_indexValueAttributes,
178182
$model->getIndexValueAttributes()
@@ -197,6 +201,7 @@ protected function initTypeModels()
197201
public function export()
198202
{
199203
//Execution time may be very long
204+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
200205
set_time_limit(0);
201206

202207
$writer = $this->getWriter();
@@ -234,16 +239,6 @@ public function filterAttributeCollection(\Magento\Eav\Model\ResourceModel\Entit
234239

235240
foreach ($collection as $attribute) {
236241
if (in_array($attribute->getAttributeCode(), $this->_disabledAttrs)) {
237-
if (isset($this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_SKIP])) {
238-
if ($attribute->getAttributeCode() == ImportAdvancedPricing::COL_TIER_PRICE
239-
&& in_array(
240-
$attribute->getId(),
241-
$this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_SKIP]
242-
)
243-
) {
244-
$this->_passTierPrice = 1;
245-
}
246-
}
247242
$collection->removeItemByKey($attribute->getId());
248243
}
249244
}
@@ -363,6 +358,7 @@ private function prepareExportData(
363358
$linkedTierPricesData = [];
364359
foreach ($tierPricesData as $tierPriceData) {
365360
$sku = $productLinkIdToSkuMap[$tierPriceData['product_link_id']];
361+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
366362
$linkedTierPricesData[] = array_merge(
367363
$tierPriceData,
368364
[ImportAdvancedPricing::COL_SKU => $sku]
@@ -471,7 +467,7 @@ private function fetchTierPrices(array $productIds): array
471467
ImportAdvancedPricing::COL_TIER_PRICE_QTY => 'ap.qty',
472468
ImportAdvancedPricing::COL_TIER_PRICE => 'ap.value',
473469
ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE => 'ap.percentage_value',
474-
'product_link_id' => 'ap.' .$productEntityLinkField,
470+
'product_link_id' => 'ap.' . $productEntityLinkField,
475471
];
476472
if ($exportFilter && array_key_exists('tier_price', $exportFilter)) {
477473
if (!empty($exportFilter['tier_price'][0])) {
@@ -488,7 +484,7 @@ private function fetchTierPrices(array $productIds): array
488484
$selectFields
489485
)
490486
->where(
491-
'ap.'.$productEntityLinkField.' IN (?)',
487+
'ap.' . $productEntityLinkField . ' IN (?)',
492488
$productIds
493489
);
494490

@@ -602,7 +598,7 @@ protected function _getWebsiteCode(int $websiteId): string
602598
}
603599

604600
if ($storeName && $currencyCode) {
605-
$code = $storeName.' ['.$currencyCode.']';
601+
$code = $storeName . ' [' . $currencyCode . ']';
606602
} else {
607603
$code = $storeName;
608604
}

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

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,9 @@ protected function initTypeModels()
484484
}
485485
if ($model->isSuitable()) {
486486
$this->_productTypeModels[$productTypeName] = $model;
487+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
487488
$this->_disabledAttrs = array_merge($this->_disabledAttrs, $model->getDisabledAttrs());
489+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
488490
$this->_indexValueAttributes = array_merge(
489491
$this->_indexValueAttributes,
490492
$model->getIndexValueAttributes()
@@ -526,7 +528,7 @@ protected function getMediaGallery(array $productIds)
526528
if (empty($productIds)) {
527529
return [];
528530
}
529-
531+
530532
$productEntityJoinField = $this->getProductEntityLinkField();
531533

532534
$select = $this->_connection->select()->from(
@@ -710,6 +712,21 @@ public function _getHeaderColumns()
710712
return $this->_customHeadersMapping($this->rowCustomizer->addHeaderColumns($this->_headerColumns));
711713
}
712714

715+
/**
716+
* Return non-system attributes
717+
718+
* @return array
719+
*/
720+
private function getNonSystemAttributes(): array
721+
{
722+
$attrKeys = [];
723+
foreach ($this->filterAttributeCollection($this->getAttributeCollection()) as $attribute) {
724+
$attrKeys[] = $attribute->getAttributeCode();
725+
}
726+
727+
return array_diff($this->_getExportMainAttrCodes(), $this->_customHeadersMapping($attrKeys));
728+
}
729+
713730
/**
714731
* Set headers columns
715732
*
@@ -722,6 +739,18 @@ public function _getHeaderColumns()
722739
*/
723740
protected function setHeaderColumns($customOptionsData, $stockItemRows)
724741
{
742+
$exportAttributes = (
743+
array_key_exists("skip_attr", $this->_parameters) && count($this->_parameters["skip_attr"])
744+
) ?
745+
array_intersect(
746+
$this->_getExportMainAttrCodes(),
747+
array_merge(
748+
$this->_customHeadersMapping($this->_getExportAttrCodes()),
749+
$this->getNonSystemAttributes()
750+
)
751+
) :
752+
$this->_getExportMainAttrCodes();
753+
725754
if (!$this->_headerColumns) {
726755
$this->_headerColumns = array_merge(
727756
[
@@ -732,7 +761,7 @@ protected function setHeaderColumns($customOptionsData, $stockItemRows)
732761
self::COL_CATEGORY,
733762
self::COL_PRODUCT_WEBSITES,
734763
],
735-
$this->_getExportMainAttrCodes(),
764+
$exportAttributes,
736765
[self::COL_ADDITIONAL_ATTRIBUTES],
737766
reset($stockItemRows) ? array_keys(end($stockItemRows)) : [],
738767
[
@@ -923,6 +952,7 @@ protected function getExportData()
923952
foreach ($rawData as $productId => $productData) {
924953
foreach ($productData as $storeId => $dataRow) {
925954
if ($storeId == Store::DEFAULT_STORE_ID && isset($stockItemRows[$productId])) {
955+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
926956
$dataRow = array_merge($dataRow, $stockItemRows[$productId]);
927957
}
928958
$this->appendMultirowData($dataRow, $multirawData);
@@ -1330,7 +1360,7 @@ private function appendMultirowData(&$dataRow, $multiRawData)
13301360
$dataRow[self::COL_SKU] = $sku;
13311361
$dataRow[self::COL_ATTR_SET] = $attributeSet;
13321362
$dataRow[self::COL_TYPE] = $type;
1333-
1363+
13341364
return $dataRow;
13351365
}
13361366

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ImportExport\Api\Data;
9+
10+
/**
11+
* Extended export interface for implementation of Skipped Attributes which are missing from the basic interface
12+
*/
13+
interface ExtendedExportInfoInterface extends ExportInfoInterface
14+
{
15+
/**
16+
* Returns skipped attributes
17+
*
18+
* @return mixed
19+
*/
20+
public function getSkipAttr();
21+
22+
/**
23+
* Set skipped attributes
24+
*
25+
* @param string $skipAttr
26+
* @return mixed
27+
*/
28+
public function setSkipAttr($skipAttr);
29+
}

app/code/Magento/ImportExport/Controller/Adminhtml/Export/Export.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
*/
66
namespace Magento\ImportExport\Controller\Adminhtml\Export;
77

8+
use Magento\Backend\App\Action\Context;
89
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
10+
use Magento\Framework\App\Response\Http\FileFactory;
911
use Magento\Framework\Controller\ResultFactory;
12+
use Magento\Framework\MessageQueue\PublisherInterface;
1013
use Magento\ImportExport\Controller\Adminhtml\Export as ExportController;
11-
use Magento\Backend\App\Action\Context;
12-
use Magento\Framework\App\Response\Http\FileFactory;
1314
use Magento\ImportExport\Model\Export as ExportModel;
14-
use Magento\Framework\MessageQueue\PublisherInterface;
1515
use Magento\ImportExport\Model\Export\Entity\ExportInfoFactory;
1616

1717
/**
@@ -76,11 +76,16 @@ public function execute()
7676
try {
7777
$params = $this->getRequest()->getParams();
7878

79+
if (!array_key_exists('skip_attr', $params)) {
80+
$params['skip_attr'] = [];
81+
}
82+
7983
/** @var ExportInfoFactory $dataObject */
8084
$dataObject = $this->exportInfoFactory->create(
8185
$params['file_format'],
8286
$params['entity'],
83-
$params['export_filter']
87+
$params['export_filter'],
88+
$params['skip_attr']
8489
);
8590

8691
$this->messagePublisher->publish('import_export.export', $dataObject);

app/code/Magento/ImportExport/Model/Export/Entity/ExportInfo.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
namespace Magento\ImportExport\Model\Export\Entity;
99

10-
use \Magento\ImportExport\Api\Data\ExportInfoInterface;
10+
use Magento\ImportExport\Api\Data\ExtendedExportInfoInterface;
1111

1212
/**
1313
* Class ExportInfo implementation for ExportInfoInterface.
1414
*/
15-
class ExportInfo implements ExportInfoInterface
15+
class ExportInfo implements ExtendedExportInfoInterface
1616
{
1717
/**
1818
* @var string
@@ -39,6 +39,11 @@ class ExportInfo implements ExportInfoInterface
3939
*/
4040
private $exportFilter;
4141

42+
/**
43+
* @var mixed
44+
*/
45+
private $skipAttr;
46+
4247
/**
4348
* @inheritdoc
4449
*/
@@ -118,4 +123,20 @@ public function setExportFilter($exportFilter)
118123
{
119124
$this->exportFilter = $exportFilter;
120125
}
126+
127+
/**
128+
* @inheritdoc
129+
*/
130+
public function getSkipAttr()
131+
{
132+
return $this->skipAttr;
133+
}
134+
135+
/**
136+
* @inheritdoc
137+
*/
138+
public function setSkipAttr($skipAttr)
139+
{
140+
$this->skipAttr = $skipAttr;
141+
}
121142
}

app/code/Magento/ImportExport/Model/Export/Entity/ExportInfoFactory.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,25 @@ public function __construct(
8484
* @param string $fileFormat
8585
* @param string $entity
8686
* @param string $exportFilter
87+
* @param array $skipAttr
8788
* @return ExportInfoInterface
8889
* @throws \Magento\Framework\Exception\LocalizedException
8990
*/
90-
public function create($fileFormat, $entity, $exportFilter)
91+
public function create($fileFormat, $entity, $exportFilter, $skipAttr)
9192
{
9293
$writer = $this->getWriter($fileFormat);
93-
$entityAdapter = $this->getEntityAdapter($entity, $fileFormat, $exportFilter, $writer->getContentType());
94+
$entityAdapter = $this->getEntityAdapter(
95+
$entity,
96+
$fileFormat,
97+
$exportFilter,
98+
$skipAttr,
99+
$writer->getContentType()
100+
);
94101
$fileName = $this->generateFileName($entity, $entityAdapter, $writer->getFileExtension());
95102
/** @var ExportInfoInterface $exportInfo */
96103
$exportInfo = $this->objectManager->create(ExportInfoInterface::class);
97104
$exportInfo->setExportFilter($this->serializer->serialize($exportFilter));
105+
$exportInfo->setSkipAttr($skipAttr);
98106
$exportInfo->setFileName($fileName);
99107
$exportInfo->setEntity($entity);
100108
$exportInfo->setFileFormat($fileFormat);
@@ -130,11 +138,12 @@ private function generateFileName($entity, $entityAdapter, $fileExtensions)
130138
* @param string $entity
131139
* @param string $fileFormat
132140
* @param string $exportFilter
141+
* @param array $skipAttr
133142
* @param string $contentType
134143
* @return \Magento\ImportExport\Model\Export\AbstractEntity|AbstractEntity
135144
* @throws \Magento\Framework\Exception\LocalizedException
136145
*/
137-
private function getEntityAdapter($entity, $fileFormat, $exportFilter, $contentType)
146+
private function getEntityAdapter($entity, $fileFormat, $exportFilter, $skipAttr, $contentType)
138147
{
139148
$entities = $this->exportConfig->getEntities();
140149
if (isset($entities[$entity])) {
@@ -166,12 +175,15 @@ private function getEntityAdapter($entity, $fileFormat, $exportFilter, $contentT
166175
} else {
167176
throw new \Magento\Framework\Exception\LocalizedException(__('Please enter a correct entity.'));
168177
}
169-
$entityAdapter->setParameters([
170-
'fileFormat' => $fileFormat,
171-
'entity' => $entity,
172-
'exportFilter' => $exportFilter,
173-
'contentType' => $contentType,
174-
]);
178+
$entityAdapter->setParameters(
179+
[
180+
'fileFormat' => $fileFormat,
181+
'entity' => $entity,
182+
'exportFilter' => $exportFilter,
183+
'skipAttr' => $skipAttr,
184+
'contentType' => $contentType,
185+
]
186+
);
175187
return $entityAdapter;
176188
}
177189

app/code/Magento/ImportExport/etc/communication.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Communication/etc/communication.xsd">
9-
<topic name="import_export.export" request="Magento\ImportExport\Api\Data\ExportInfoInterface">
9+
<topic name="import_export.export" request="Magento\ImportExport\Api\Data\ExtendedExportInfoInterface">
1010
<handler name="exportProcessor" type="Magento\ImportExport\Model\Export\Consumer" method="process" />
1111
</topic>
1212
</config>

app/code/Magento/ImportExport/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<preference for="Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface" type="Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregator" />
1212
<preference for="Magento\ImportExport\Model\Report\ReportProcessorInterface" type="Magento\ImportExport\Model\Report\Csv" />
1313
<preference for="Magento\ImportExport\Api\Data\ExportInfoInterface" type="Magento\ImportExport\Model\Export\Entity\ExportInfo" />
14+
<preference for="Magento\ImportExport\Api\Data\ExtendedExportInfoInterface" type="Magento\ImportExport\Model\Export\Entity\ExportInfo" />
1415
<preference for="Magento\ImportExport\Api\ExportManagementInterface" type="Magento\ImportExport\Model\Export\ExportManagement" />
1516
<type name="Magento\Framework\Module\Setup\Migration">
1617
<arguments>

0 commit comments

Comments
 (0)