Skip to content

Commit 3b1c8c5

Browse files
committed
MC-33499: Grid Filter not working for Scheduled Export when selected any kind of Entity Type
1 parent 8e998d3 commit 3b1c8c5

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

app/code/Magento/ImportExport/Block/Adminhtml/Export/Filter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ public function prepareCollection(\Magento\Framework\Data\Collection $collection
440440
$attributeGridCollection = $this->attributeGridCollectionFactory->create();
441441
$gridCollection = $attributeGridCollection->setItems($collection->getItems());
442442
$this->setCollection($gridCollection);
443+
443444
return $collection;
444445
}
445446
}

app/code/Magento/ImportExport/Model/ResourceModel/Export/AttributeGridCollection.php

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
class AttributeGridCollection extends Collection
1616
{
17+
private const FILTERED_FLAG_NAME = 'agc_filtered';
1718

1819
/**
1920
* Adding item to collection
@@ -32,8 +33,6 @@ public function setItems(array $items): self
3233

3334
/**
3435
* @inheritDoc
35-
*
36-
* @return int
3736
*/
3837
public function getSize(): int
3938
{
@@ -42,10 +41,6 @@ public function getSize(): int
4241

4342
/**
4443
* @inheritDoc
45-
*
46-
* @param string $field
47-
* @param array|int|string $condition
48-
* @return $this
4944
*/
5045
public function addFieldToFilter($field, $condition)
5146
{
@@ -59,28 +54,48 @@ public function addFieldToFilter($field, $condition)
5954

6055
/**
6156
* @inheritDoc
57+
*/
58+
public function load($printQuery = false, $logQuery = false)
59+
{
60+
$this->filterCollection();
61+
$this->sortCollectionByAttributeCode();
62+
63+
return $this;
64+
}
65+
66+
/**
67+
* Add filters to collection
6268
*
63-
* @param false $printQuery
64-
* @param false $logQuery
6569
* @return $this
6670
*/
67-
public function load($printQuery = false, $logQuery = false)
71+
private function filterCollection()
6872
{
69-
if (!$this->getFlag('isFilter') && !empty($this->_filters)) {
73+
if (!$this->getFlag(self::FILTERED_FLAG_NAME) && !empty($this->_filters)) {
7074
foreach ($this->_filters as $filter) {
7175
foreach ($this->_items as $item) {
7276
$field = $item->getData($filter->getData('field')) ?? '';
7377
if (stripos($field, $filter->getData('value')) === false) {
7478
$this->removeItemByKey($item->getId());
7579
}
7680
}
77-
$this->setFlag('isFilter', true);
7881
}
82+
$this->setFlag(self::FILTERED_FLAG_NAME, true);
7983
}
8084

85+
return $this;
86+
}
87+
88+
/**
89+
* Sort collection by attribute code
90+
*
91+
* @return $this
92+
*/
93+
private function sortCollectionByAttributeCode()
94+
{
8195
$sortOrder = $this->_orders['attribute_code'];
8296
uasort($this->_items, function ($a, $b) use ($sortOrder) {
8397
$cmp = strnatcmp($a->getData('attribute_code'), $b->getData('attribute_code'));
98+
8499
return $sortOrder === self::SORT_ORDER_ASC ? $cmp : -$cmp;
85100
});
86101

0 commit comments

Comments
 (0)