Skip to content

Commit 49f1c8f

Browse files
MAGETWO-82487: FIX #11022 in 2.1-develop: Filter Groups of search criteria parameter have not been included for further processing #11432
2 parents 2579722 + 55d0bba commit 49f1c8f

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/SetRepository.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function save(\Magento\Eav\Api\Data\AttributeSetInterface $attributeSet)
6262
*/
6363
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
6464
{
65+
$this->searchCriteriaBuilder->setFilterGroups((array)$searchCriteria->getFilterGroups());
6566
$this->searchCriteriaBuilder->addFilters(
6667
[
6768
$this->filterBuilder
@@ -71,9 +72,15 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
7172
->create(),
7273
]
7374
);
75+
76+
$this->searchCriteriaBuilder->setSortOrders((array)$searchCriteria->getSortOrders());
7477
$this->searchCriteriaBuilder->setCurrentPage($searchCriteria->getCurrentPage());
7578
$this->searchCriteriaBuilder->setPageSize($searchCriteria->getPageSize());
76-
return $this->attributeSetRepository->getList($this->searchCriteriaBuilder->create());
79+
80+
$searchResult = $this->attributeSetRepository->getList($this->searchCriteriaBuilder->create());
81+
$searchResult->setSearchCriteria($searchCriteria);
82+
83+
return $searchResult;
7784
}
7885

7986
/**

app/code/Magento/Eav/Model/AttributeSetRepository.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
105105
$collection->setEntityTypeFilter($this->eavConfig->getEntityType($entityTypeCode)->getId());
106106
}
107107

108+
foreach ($searchCriteria->getFilterGroups() as $group) {
109+
$this->addFilterGroupToCollection($group, $collection);
110+
}
111+
108112
$collection->setCurPage($searchCriteria->getCurrentPage());
109113
$collection->setPageSize($searchCriteria->getPageSize());
110114

@@ -115,6 +119,29 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
115119
return $searchResults;
116120
}
117121

122+
/**
123+
* Helper function that adds a FilterGroup to the collection.
124+
*
125+
* @deprecated already removed in 2.2-develop. Use CollectionProcessorInterface to process search criteria
126+
*
127+
* @param \Magento\Framework\Api\Search\FilterGroup $filterGroup
128+
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection $collection
129+
* @return void
130+
*/
131+
private function addFilterGroupToCollection(
132+
\Magento\Framework\Api\Search\FilterGroup $filterGroup,
133+
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection $collection
134+
) {
135+
foreach ($filterGroup->getFilters() as $filter) {
136+
/** entity type filter is already set on collection */
137+
if ($filter->getField() === 'entity_type_code') {
138+
continue;
139+
}
140+
$conditionType = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
141+
$collection->addFieldToFilter($filter->getField(), [$conditionType, $filter->getValue()]);
142+
}
143+
}
144+
118145
/**
119146
* Retrieve entity type code from search criteria
120147
*

app/code/Magento/Eav/Test/Unit/Model/AttributeSetRepositoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,12 @@ public function testGetList()
212212
$searchCriteriaMock = $this->getMock('\Magento\Framework\Api\SearchCriteriaInterface');
213213

214214
$filterGroupMock = $this->getMock('\Magento\Framework\Api\Search\FilterGroup', [], [], '', false);
215-
$searchCriteriaMock->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroupMock]);
215+
$searchCriteriaMock->expects($this->exactly(2))->method('getFilterGroups')->willReturn([$filterGroupMock]);
216216

217217
$filterMock = $this->getMock('\Magento\Framework\Api\Filter', [], [], '', false);
218-
$filterGroupMock->expects($this->once())->method('getFilters')->willReturn([$filterMock]);
218+
$filterGroupMock->expects($this->exactly(2))->method('getFilters')->willReturn([$filterMock]);
219219

220-
$filterMock->expects($this->once())->method('getField')->willReturn('entity_type_code');
220+
$filterMock->expects($this->exactly(2))->method('getField')->willReturn('entity_type_code');
221221
$filterMock->expects($this->once())->method('getValue')->willReturn($entityTypeCode);
222222

223223
$collectionMock = $this->getMock(
@@ -273,7 +273,7 @@ public function testGetList()
273273
public function testGetListIfEntityTypeCodeIsNull()
274274
{
275275
$searchCriteriaMock = $this->getMock('\Magento\Framework\Api\SearchCriteriaInterface');
276-
$searchCriteriaMock->expects($this->once())->method('getFilterGroups')->willReturn([]);
276+
$searchCriteriaMock->expects($this->exactly(2))->method('getFilterGroups')->willReturn([]);
277277

278278
$collectionMock = $this->getMock(
279279
'\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection',

dev/tests/api-functional/testsuite/Magento/Catalog/Api/AttributeSetRepositoryTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,9 @@ public function testGetList()
165165
{
166166
$searchCriteria = [
167167
'searchCriteria' => [
168-
'filter_groups' => [
169-
[
170-
'filters' => [
171-
[
172-
'field' => 'entity_type_code',
173-
'value' => 'catalog_product',
174-
'condition_type' => 'eq',
175-
],
176-
],
177-
],
178-
],
168+
'filter_groups' => [],
179169
'current_page' => 1,
180-
'page_size' => 2,
170+
'page_size' => 2
181171
],
182172
];
183173

0 commit comments

Comments
 (0)