Skip to content

Commit 2c23dea

Browse files
committed
ACP2E-294: Category Ids Not Available in scheduled Export Filters
1 parent 0809359 commit 2c23dea

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

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

Lines changed: 10 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
{
@@ -335,6 +336,7 @@ protected function _prepareEntityCollection(\Magento\Eav\Model\Entity\Collection
335336
}
336337
return $collection;
337338
}
339+
//phpcs:enable Generic.Metrics.NestingLevel
338340

339341
/**
340342
* Add error with corresponding current data source row number.
@@ -348,6 +350,7 @@ public function addRowError($errorCode, $errorRowNum)
348350
$errorCode = (string)$errorCode;
349351
$this->_errors[$errorCode][] = $errorRowNum + 1;
350352
// one added for human readability
353+
// phpstan:ignore "Access to an undefined property"
351354
$this->_invalidRows[$errorRowNum] = true;
352355
$this->_errorsCount++;
353356

@@ -440,6 +443,7 @@ public function getAttributeOptions(\Magento\Eav\Model\Entity\Attribute\Abstract
440443
}
441444
}
442445
}
446+
// phpcs:disable Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
443447
} catch (\Exception $e) {
444448
// ignore exceptions connected with source models
445449
}
@@ -504,6 +508,7 @@ public function getErrorsCount()
504508
*/
505509
public function getInvalidRowsCount()
506510
{
511+
// phpstan:ignore "Access to an undefined property"
507512
return count($this->_invalidRows);
508513
}
509514

@@ -569,6 +574,7 @@ public function setWriter(AbstractAdapter $writer)
569574

570575
/**
571576
* Clean cached values
577+
*
572578
* @since 100.1.2
573579
*/
574580
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)