Skip to content

Commit 8e998d3

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

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

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

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Framework\Data\Collection;
1111

1212
/**
13-
* Class AttributeGridCollection
13+
* Association of attributes for grid
1414
*/
1515
class AttributeGridCollection extends Collection
1616
{
@@ -49,45 +49,41 @@ public function getSize(): int
4949
*/
5050
public function addFieldToFilter($field, $condition)
5151
{
52-
$value = (string)$condition['like'];
53-
$value = trim(trim($value, "'"), "%");
54-
foreach ($this->getItems() as $item) {
55-
if (stripos($item->getData($field), $value) === false) {
56-
$this->removeItemByKey($item->getId());
57-
}
52+
if (isset($condition['like'])) {
53+
$value = trim((string)$condition['like'], "'%");
54+
$this->addFilter($field, $value);
5855
}
5956

6057
return $this;
6158
}
6259

6360
/**
64-
* Add select order
61+
* @inheritDoc
6562
*
66-
* @param string $field
67-
* @param string $direction
63+
* @param false $printQuery
64+
* @param false $logQuery
6865
* @return $this
6966
*/
70-
public function setOrder($field, $direction = self::SORT_ORDER_DESC)
67+
public function load($printQuery = false, $logQuery = false)
7168
{
72-
$this->_orderField = $field;
73-
uasort($this->_items, [$this, 'compareAttributes']);
74-
75-
if ($direction == self::SORT_ORDER_DESC) {
76-
$this->_items = array_reverse($this->_items, true);
69+
if (!$this->getFlag('isFilter') && !empty($this->_filters)) {
70+
foreach ($this->_filters as $filter) {
71+
foreach ($this->_items as $item) {
72+
$field = $item->getData($filter->getData('field')) ?? '';
73+
if (stripos($field, $filter->getData('value')) === false) {
74+
$this->removeItemByKey($item->getId());
75+
}
76+
}
77+
$this->setFlag('isFilter', true);
78+
}
7779
}
7880

79-
return $this;
80-
}
81+
$sortOrder = $this->_orders['attribute_code'];
82+
uasort($this->_items, function ($a, $b) use ($sortOrder) {
83+
$cmp = strnatcmp($a->getData('attribute_code'), $b->getData('attribute_code'));
84+
return $sortOrder === self::SORT_ORDER_ASC ? $cmp : -$cmp;
85+
});
8186

82-
/**
83-
* Compare two collection items
84-
*
85-
* @param \Magento\Framework\DataObject $a
86-
* @param \Magento\Framework\DataObject $b
87-
* @return int
88-
*/
89-
public function compareAttributes(\Magento\Framework\DataObject $a, \Magento\Framework\DataObject $b)
90-
{
91-
return strnatcmp($a->getData($this->_orderField), $b->getData($this->_orderField));
87+
return $this;
9288
}
9389
}

0 commit comments

Comments
 (0)