Skip to content

Commit 0973d97

Browse files
[Magento Community Engineering] Community Contributions - 2.3-develop
- merged latest code from mainline branch
2 parents 02bc4a9 + fc6b5aa commit 0973d97

File tree

18 files changed

+1148
-656
lines changed

18 files changed

+1148
-656
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

app/code/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/**
1414
* Import entity abstract product type model
1515
*
16+
* phpcs:disable Magento2.Classes.AbstractApi
1617
* @api
1718
*
1819
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -543,7 +544,7 @@ public function prepareAttributesWithDefaultValueForSave(array $rowData, $withDe
543544
} else {
544545
$resultAttrs[$attrCode] = $rowData[$attrCode];
545546
}
546-
} elseif (array_key_exists($attrCode, $rowData) && empty($rowData['_store'])) {
547+
} elseif (array_key_exists($attrCode, $rowData)) {
547548
$resultAttrs[$attrCode] = $rowData[$attrCode];
548549
} elseif ($withDefaultValue && null !== $attrParams['default_value'] && empty($rowData['_store'])) {
549550
$resultAttrs[$attrCode] = $attrParams['default_value'];

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Type/AbstractTypeTest.php

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ protected function setUp()
7272
'setAttributeSetFilter'
7373
]
7474
);
75-
$attribute = $this->createPartialMock(\Magento\Eav\Model\Entity\Attribute::class, [
75+
$attribute = $this->createPartialMock(
76+
\Magento\Eav\Model\Entity\Attribute::class,
77+
[
7678
'getAttributeCode',
7779
'getId',
7880
'getIsVisible',
@@ -85,7 +87,8 @@ protected function setUp()
8587
'getDefaultValue',
8688
'usesSource',
8789
'getFrontendInput',
88-
]);
90+
]
91+
);
8992
$attribute->expects($this->any())->method('getIsVisible')->willReturn(true);
9093
$attribute->expects($this->any())->method('getIsGlobal')->willReturn(true);
9194
$attribute->expects($this->any())->method('getIsRequired')->willReturn(true);
@@ -107,6 +110,7 @@ protected function setUp()
107110
];
108111
$attribute1 = clone $attribute;
109112
$attribute2 = clone $attribute;
113+
$attribute3 = clone $attribute;
110114

111115
$attribute1->expects($this->any())->method('getId')->willReturn('1');
112116
$attribute1->expects($this->any())->method('getAttributeCode')->willReturn('attr_code');
@@ -118,6 +122,11 @@ protected function setUp()
118122
$attribute2->expects($this->any())->method('getFrontendInput')->willReturn('boolean');
119123
$attribute2->expects($this->any())->method('isStatic')->willReturn(false);
120124

125+
$attribute3->expects($this->any())->method('getId')->willReturn('3');
126+
$attribute3->expects($this->any())->method('getAttributeCode')->willReturn('text_attribute');
127+
$attribute3->expects($this->any())->method('getFrontendInput')->willReturn('text');
128+
$attribute3->expects($this->any())->method('isStatic')->willReturn(false);
129+
121130
$this->entityModel->expects($this->any())->method('getEntityTypeId')->willReturn(3);
122131
$this->entityModel->expects($this->any())->method('getAttributeOptions')->willReturnOnConsecutiveCalls(
123132
['option1', 'option2'],
@@ -126,7 +135,9 @@ protected function setUp()
126135
$attrSetColFactory->expects($this->any())->method('create')->willReturn($attrSetCollection);
127136
$attrSetCollection->expects($this->any())->method('setEntityTypeFilter')->willReturn([$attributeSet]);
128137
$attrColFactory->expects($this->any())->method('create')->willReturn($attrCollection);
129-
$attrCollection->expects($this->any())->method('setAttributeSetFilter')->willReturn([$attribute1, $attribute2]);
138+
$attrCollection->expects($this->any())
139+
->method('setAttributeSetFilter')
140+
->willReturn([$attribute1, $attribute2, $attribute3]);
130141
$attributeSet->expects($this->any())->method('getId')->willReturn(1);
131142
$attributeSet->expects($this->any())->method('getAttributeSetName')->willReturn('attribute_set_name');
132143

@@ -157,23 +168,29 @@ protected function setUp()
157168
],
158169
]
159170
)
160-
->willReturn([$attribute1, $attribute2]);
171+
->willReturn([$attribute1, $attribute2, $attribute3]);
161172

162-
$this->connection = $this->createPartialMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class, [
173+
$this->connection = $this->createPartialMock(
174+
\Magento\Framework\DB\Adapter\Pdo\Mysql::class,
175+
[
163176
'select',
164177
'fetchAll',
165178
'fetchPairs',
166179
'joinLeft',
167180
'insertOnDuplicate',
168181
'delete',
169182
'quoteInto'
170-
]);
171-
$this->select = $this->createPartialMock(\Magento\Framework\DB\Select::class, [
183+
]
184+
);
185+
$this->select = $this->createPartialMock(
186+
\Magento\Framework\DB\Select::class,
187+
[
172188
'from',
173189
'where',
174190
'joinLeft',
175191
'getConnection',
176-
]);
192+
]
193+
);
177194
$this->select->expects($this->any())->method('from')->will($this->returnSelf());
178195
$this->select->expects($this->any())->method('where')->will($this->returnSelf());
179196
$this->select->expects($this->any())->method('joinLeft')->will($this->returnSelf());
@@ -189,10 +206,13 @@ protected function setUp()
189206
->method('fetchAll')
190207
->will($this->returnValue($entityAttributes));
191208

192-
$this->resource = $this->createPartialMock(\Magento\Framework\App\ResourceConnection::class, [
209+
$this->resource = $this->createPartialMock(
210+
\Magento\Framework\App\ResourceConnection::class,
211+
[
193212
'getConnection',
194213
'getTableName',
195-
]);
214+
]
215+
);
196216
$this->resource->expects($this->any())->method('getConnection')->will(
197217
$this->returnValue($this->connection)
198218
);
@@ -257,9 +277,13 @@ public function testIsRowValidSuccess()
257277
$rowNum = 1;
258278
$this->entityModel->expects($this->any())->method('getRowScope')->willReturn(null);
259279
$this->entityModel->expects($this->never())->method('addRowError');
260-
$this->setPropertyValue($this->simpleType, '_attributes', [
261-
$rowData[\Magento\CatalogImportExport\Model\Import\Product::COL_ATTR_SET] => [],
262-
]);
280+
$this->setPropertyValue(
281+
$this->simpleType,
282+
'_attributes',
283+
[
284+
$rowData[\Magento\CatalogImportExport\Model\Import\Product::COL_ATTR_SET] => [],
285+
]
286+
);
263287
$this->assertTrue($this->simpleType->isRowValid($rowData, $rowNum));
264288
}
265289

@@ -278,13 +302,17 @@ public function testIsRowValidError()
278302
'attr_code'
279303
)
280304
->willReturnSelf();
281-
$this->setPropertyValue($this->simpleType, '_attributes', [
282-
$rowData[\Magento\CatalogImportExport\Model\Import\Product::COL_ATTR_SET] => [
283-
'attr_code' => [
284-
'is_required' => true,
305+
$this->setPropertyValue(
306+
$this->simpleType,
307+
'_attributes',
308+
[
309+
$rowData[\Magento\CatalogImportExport\Model\Import\Product::COL_ATTR_SET] => [
310+
'attr_code' => [
311+
'is_required' => true,
312+
],
285313
],
286-
],
287-
]);
314+
]
315+
);
288316

289317
$this->assertFalse($this->simpleType->isRowValid($rowData, $rowNum));
290318
}
@@ -364,9 +392,14 @@ public function testPrepareAttributesWithDefaultValueForSave()
364392
{
365393
$rowData = [
366394
'_attribute_set' => 'attributeSetName',
367-
'boolean_attribute' => 'Yes'
395+
'boolean_attribute' => 'Yes',
396+
];
397+
398+
$expected = [
399+
'boolean_attribute' => 1,
400+
'text_attribute' => 'default_value'
368401
];
369402
$result = $this->simpleType->prepareAttributesWithDefaultValueForSave($rowData);
370-
$this->assertEquals(['boolean_attribute' => 1], $result);
403+
$this->assertEquals($expected, $result);
371404
}
372405
}
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+
}

0 commit comments

Comments
 (0)