Skip to content

FIX #11022 in 2.1-develop: Filter Groups of search criteria parameter have not been included for further processing #11432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function save(\Magento\Eav\Api\Data\AttributeSetInterface $attributeSet)
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
{
$this->searchCriteriaBuilder->setFilterGroups((array)$searchCriteria->getFilterGroups());
$this->searchCriteriaBuilder->addFilters(
[
$this->filterBuilder
Expand All @@ -71,9 +72,15 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
->create(),
]
);

$this->searchCriteriaBuilder->setSortOrders((array)$searchCriteria->getSortOrders());
$this->searchCriteriaBuilder->setCurrentPage($searchCriteria->getCurrentPage());
$this->searchCriteriaBuilder->setPageSize($searchCriteria->getPageSize());
return $this->attributeSetRepository->getList($this->searchCriteriaBuilder->create());

$searchResult = $this->attributeSetRepository->getList($this->searchCriteriaBuilder->create());
$searchResult->setSearchCriteria($searchCriteria);

return $searchResult;
}

/**
Expand Down
27 changes: 27 additions & 0 deletions app/code/Magento/Eav/Model/AttributeSetRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
$collection->setEntityTypeFilter($this->eavConfig->getEntityType($entityTypeCode)->getId());
}

foreach ($searchCriteria->getFilterGroups() as $group) {
$this->addFilterGroupToCollection($group, $collection);
}

$collection->setCurPage($searchCriteria->getCurrentPage());
$collection->setPageSize($searchCriteria->getPageSize());

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

/**
* Helper function that adds a FilterGroup to the collection.
*
* @deprecated already removed in 2.2-develop. Use CollectionProcessorInterface to process search criteria
*
* @param \Magento\Framework\Api\Search\FilterGroup $filterGroup
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection $collection
* @return void
*/
private function addFilterGroupToCollection(
\Magento\Framework\Api\Search\FilterGroup $filterGroup,
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection $collection
) {
foreach ($filterGroup->getFilters() as $filter) {
/** entity type filter is already set on collection */
if ($filter->getField() === 'entity_type_code') {
continue;
}
$conditionType = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
$collection->addFieldToFilter($filter->getField(), [$conditionType, $filter->getValue()]);
}
}

/**
* Retrieve entity type code from search criteria
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,12 @@ public function testGetList()
$searchCriteriaMock = $this->getMock('\Magento\Framework\Api\SearchCriteriaInterface');

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

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

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

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

$collectionMock = $this->getMock(
'\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,9 @@ public function testGetList()
{
$searchCriteria = [
'searchCriteria' => [
'filter_groups' => [
[
'filters' => [
[
'field' => 'entity_type_code',
'value' => 'catalog_product',
'condition_type' => 'eq',
],
],
],
],
'filter_groups' => [],
'current_page' => 1,
'page_size' => 2,
'page_size' => 2
],
];

Expand Down