Skip to content

Commit fa8d847

Browse files
committed
Merge remote-tracking branch 'l3/ACP2E-294' into PR_L3_22_04_2022
2 parents 5d6a1ba + c3719d7 commit fa8d847

File tree

7 files changed

+44
-7
lines changed

7 files changed

+44
-7
lines changed

app/code/Magento/AdvancedPricingImportExport/Controller/Adminhtml/Export/GetFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public function execute()
3434
/** @var $export \Magento\ImportExport\Model\Export */
3535
$export = $this->_objectManager->create(\Magento\ImportExport\Model\Export::class);
3636
$export->setData($data);
37-
$export->filterAttributeCollection(
38-
$attrFilterBlock->prepareCollection($export->getEntityAttributeCollection())
37+
$attrFilterBlock->prepareCollection(
38+
$export->filterAttributeCollection($export->getEntityAttributeCollection())
3939
);
4040
return $resultLayout;
4141
} catch (\Exception $e) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function filter(Collection $collection, array $filters): Collection
2525
$value = trim($filters[self::NAME] ?? '');
2626
if ($value) {
2727
$collection->addCategoriesFilter(['in' => explode(',', $value)]);
28+
$collection->setFlag(self::NAME . '_filter_applied');
2829
}
2930
return $collection;
3031
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ public function filter(Collection $collection, array $filters): Collection
4848
switch ($value) {
4949
case self::IN_STOCK:
5050
$this->stockHelper->addInStockFilterToCollection($collection);
51+
$collection->setFlag(self::NAME . '_filter_applied');
5152
break;
5253
case self::OUT_OF_STOCK:
5354
$this->stockHelper->addOutOfStockFilterToCollection($collection);
55+
$collection->setFlag(self::NAME . '_filter_applied');
5456
break;
5557
}
5658
return $collection;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class Simple extends \Magento\CatalogImportExport\Model\Export\Product\Type\Abst
3333
protected $_disabledAttrs = [
3434
'old_id',
3535
'tier_price',
36-
'category_ids',
3736
'has_options',
3837
'is_returnable',
3938
'required_options',

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function filter(Collection $collection, array $filters): Collection
2727
}
2828

2929
$collection->addWebsiteFilter($filters[self::NAME]);
30+
$collection->setFlag(self::NAME . '_filter_applied');
3031

3132
return $collection;
3233
}

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/**
1212
* Export entity abstract model
1313
*
14+
* phpcs:ignore Magento2.Classes.AbstractApi
1415
* @api
1516
*
1617
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -48,8 +49,6 @@ abstract class AbstractEntity
4849
protected $_disabledAttrs = [];
4950

5051
/**
51-
* Entity type id.
52-
*
5352
* @var int
5453
*/
5554
protected $_entityTypeId;
@@ -97,8 +96,6 @@ abstract class AbstractEntity
9796
protected $_messageTemplates = [];
9897

9998
/**
100-
* Parameters.
101-
*
10299
* @var array
103100
*/
104101
protected $_parameters = [];
@@ -175,8 +172,10 @@ public function __construct(
175172
protected function _initStores()
176173
{
177174
foreach ($this->_storeManager->getStores(true) as $store) {
175+
// phpstan:ignore "Access to an undefined property"
178176
$this->_storeIdToCode[$store->getId()] = $store->getCode();
179177
}
178+
// phpstan:ignore "Access to an undefined property"
180179
ksort($this->_storeIdToCode);
181180
// to ensure that 'admin' store (ID is zero) goes first
182181

@@ -251,6 +250,8 @@ protected function _initAttrValues()
251250
* @param \Magento\Eav\Model\Entity\Collection\AbstractCollection $collection
252251
* @return \Magento\Eav\Model\Entity\Collection\AbstractCollection
253252
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
253+
* @SuppressWarnings(PHPMD.NPathComplexity)
254+
* phpcs:disable Generic.Metrics.NestingLevel
254255
*/
255256
protected function _prepareEntityCollection(\Magento\Eav\Model\Entity\Collection\AbstractCollection $collection)
256257
{
@@ -269,6 +270,11 @@ protected function _prepareEntityCollection(\Magento\Eav\Model\Entity\Collection
269270
foreach ($this->filterAttributeCollection($this->getAttributeCollection()) as $attribute) {
270271
$attrCode = $attribute->getAttributeCode();
271272

273+
$filterFlagName = $attrCode . '_filter_applied';
274+
if ($collection->hasFlag($filterFlagName)) {
275+
continue;
276+
}
277+
272278
// filter applying
273279
if (isset($exportFilter[$attrCode])) {
274280
$attrFilterType = \Magento\ImportExport\Model\Export::getAttributeFilterType($attribute);
@@ -320,13 +326,17 @@ protected function _prepareEntityCollection(\Magento\Eav\Model\Entity\Collection
320326
}
321327
}
322328
}
329+
330+
$collection->setFlag($filterFlagName);
323331
}
332+
324333
if (in_array($attrCode, $exportAttrCodes)) {
325334
$collection->addAttributeToSelect($attrCode);
326335
}
327336
}
328337
return $collection;
329338
}
339+
//phpcs:enable Generic.Metrics.NestingLevel
330340

331341
/**
332342
* Add error with corresponding current data source row number.
@@ -340,6 +350,7 @@ public function addRowError($errorCode, $errorRowNum)
340350
$errorCode = (string)$errorCode;
341351
$this->_errors[$errorCode][] = $errorRowNum + 1;
342352
// one added for human readability
353+
// phpstan:ignore "Access to an undefined property"
343354
$this->_invalidRows[$errorRowNum] = true;
344355
$this->_errorsCount++;
345356

@@ -432,6 +443,7 @@ public function getAttributeOptions(\Magento\Eav\Model\Entity\Attribute\Abstract
432443
}
433444
}
434445
}
446+
// phpcs:disable Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
435447
} catch (\Exception $e) {
436448
// ignore exceptions connected with source models
437449
}
@@ -496,6 +508,7 @@ public function getErrorsCount()
496508
*/
497509
public function getInvalidRowsCount()
498510
{
511+
// phpstan:ignore "Access to an undefined property"
499512
return count($this->_invalidRows);
500513
}
501514

@@ -561,6 +574,7 @@ public function setWriter(AbstractAdapter $writer)
561574

562575
/**
563576
* Clean cached values
577+
*
564578
* @since 100.1.2
565579
*/
566580
public function __destruct()

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Export/ProductTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
namespace Magento\CatalogImportExport\Model\Export;
1010

1111
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection as ProductAttributeCollection;
1213
use Magento\Catalog\Observer\SwitchPriceAttributeScopeOnConfigChange;
14+
use Magento\CatalogImportExport\Model\Export\Product\Type\Simple as SimpleProductType;
1315
use Magento\Framework\App\Config\ReinitableConfigInterface;
1416

1517
/**
@@ -711,6 +713,24 @@ public function testExportProductWithRestrictedWebsite(): void
711713
$this->assertStringNotContainsString('"Virtual Product With Custom Options"', $exportData);
712714
}
713715

716+
public function testFilterAttributeCollection(): void
717+
{
718+
$collection = $this->objectManager->create(ProductAttributeCollection::class);
719+
$collection = $this->model->filterAttributeCollection($collection);
720+
$attributes = [];
721+
foreach ($collection->getItems() as $attribute) {
722+
$attributes[] = $attribute->getAttributeCode();
723+
}
724+
725+
$simpleProductType = $this->objectManager->create(SimpleProductType::class);
726+
$disabledAttributes = $simpleProductType->getDisabledAttrs();
727+
$this->assertEmpty(
728+
array_intersect($disabledAttributes, $attributes),
729+
'Disabled attributes are not filtered.'
730+
);
731+
$this->assertContains('category_ids', $attributes);
732+
}
733+
714734
/**
715735
* Perform export
716736
*

0 commit comments

Comments
 (0)