Skip to content

Commit

Permalink
MAGETWO-82487: FIX #11022 in 2.1-develop: Filter Groups of search cri…
Browse files Browse the repository at this point in the history
…teria parameter have not been included for further processing #11432
  • Loading branch information
ishakhsuvarov authored Nov 9, 2017
2 parents 2579722 + 55d0bba commit 49f1c8f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
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

0 comments on commit 49f1c8f

Please sign in to comment.