From 93a0e5773fe283eac3890835469032eb75d02fd2 Mon Sep 17 00:00:00 2001 From: David Verholen Date: Fri, 13 Oct 2017 11:15:46 +0200 Subject: [PATCH 1/7] [BUGFIX][11022] include original search criteria #fixes 11022 --- .../Magento/Catalog/Model/Product/Attribute/SetRepository.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/SetRepository.php b/app/code/Magento/Catalog/Model/Product/Attribute/SetRepository.php index dac53e1c4078e..7d5723aa6f14d 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/SetRepository.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/SetRepository.php @@ -62,6 +62,7 @@ public function save(\Magento\Eav\Api\Data\AttributeSetInterface $attributeSet) */ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) { + $this->searchCriteriaBuilder->setFilterGroups($searchCriteria->getFilterGroups()); $this->searchCriteriaBuilder->addFilters( [ $this->filterBuilder @@ -71,6 +72,7 @@ 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()); From 051f95dfc7538309f87820601363b65e43ef17ae Mon Sep 17 00:00:00 2001 From: David Verholen Date: Fri, 13 Oct 2017 15:17:23 +0200 Subject: [PATCH 2/7] [BUGFIX][11022] return original search criteria in search result --- .../Model/Product/Attribute/SetRepository.php | 7 ++++++- .../Catalog/Api/AttributeSetRepositoryTest.php | 14 ++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/SetRepository.php b/app/code/Magento/Catalog/Model/Product/Attribute/SetRepository.php index 7d5723aa6f14d..e6b48fdfe9ecb 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/SetRepository.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/SetRepository.php @@ -72,10 +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; } /** diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/AttributeSetRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/AttributeSetRepositoryTest.php index 4973be7c8b69a..e2a1ac3f4a4da 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/AttributeSetRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/AttributeSetRepositoryTest.php @@ -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 ], ]; From 525f90a0494fd368f09a4a64e56009a18b7cb4f7 Mon Sep 17 00:00:00 2001 From: David Verholen Date: Fri, 13 Oct 2017 15:18:40 +0200 Subject: [PATCH 3/7] [BUGFIX][11022] typecast filtergroups array --- .../Magento/Catalog/Model/Product/Attribute/SetRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/SetRepository.php b/app/code/Magento/Catalog/Model/Product/Attribute/SetRepository.php index e6b48fdfe9ecb..015d37f7e3dc6 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/SetRepository.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/SetRepository.php @@ -62,7 +62,7 @@ public function save(\Magento\Eav\Api\Data\AttributeSetInterface $attributeSet) */ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) { - $this->searchCriteriaBuilder->setFilterGroups($searchCriteria->getFilterGroups()); + $this->searchCriteriaBuilder->setFilterGroups((array)$searchCriteria->getFilterGroups()); $this->searchCriteriaBuilder->addFilters( [ $this->filterBuilder From 6862394aa03f318db92164efbe7eb47125891447 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 3 Nov 2017 09:52:01 +0100 Subject: [PATCH 4/7] [BUGFIX][11022] process search criteria fields on eav collection --- .../Eav/Model/AttributeSetRepository.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/code/Magento/Eav/Model/AttributeSetRepository.php b/app/code/Magento/Eav/Model/AttributeSetRepository.php index c6c6f6b6686dd..fb9a53b422ba9 100644 --- a/app/code/Magento/Eav/Model/AttributeSetRepository.php +++ b/app/code/Magento/Eav/Model/AttributeSetRepository.php @@ -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()); @@ -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 + */ + protected 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 * From a3f30900c8292a0a905d242537f0f5ddd4a0c8fb Mon Sep 17 00:00:00 2001 From: David Date: Fri, 3 Nov 2017 15:23:07 +0100 Subject: [PATCH 5/7] [BUGFIX][11022] set function scope to private, fix unit tests --- app/code/Magento/Eav/Model/AttributeSetRepository.php | 2 +- .../Eav/Test/Unit/Model/AttributeSetRepositoryTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Eav/Model/AttributeSetRepository.php b/app/code/Magento/Eav/Model/AttributeSetRepository.php index fb9a53b422ba9..524402898656e 100644 --- a/app/code/Magento/Eav/Model/AttributeSetRepository.php +++ b/app/code/Magento/Eav/Model/AttributeSetRepository.php @@ -128,7 +128,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection $collection * @return void */ - protected function addFilterGroupToCollection( + private function addFilterGroupToCollection( \Magento\Framework\Api\Search\FilterGroup $filterGroup, \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection $collection ) { diff --git a/app/code/Magento/Eav/Test/Unit/Model/AttributeSetRepositoryTest.php b/app/code/Magento/Eav/Test/Unit/Model/AttributeSetRepositoryTest.php index 6fae6d9efec17..1f8b53f8a70a1 100644 --- a/app/code/Magento/Eav/Test/Unit/Model/AttributeSetRepositoryTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/AttributeSetRepositoryTest.php @@ -212,7 +212,7 @@ 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]); @@ -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', From 2a3ac2d6390dde25bf31afe2dd97e177ef0d6637 Mon Sep 17 00:00:00 2001 From: David Verholen Date: Sat, 4 Nov 2017 14:22:06 +0100 Subject: [PATCH 6/7] [BUGFIX][11022] fix unit tests. Expect get filters to be called twice --- .../Magento/Eav/Test/Unit/Model/AttributeSetRepositoryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Eav/Test/Unit/Model/AttributeSetRepositoryTest.php b/app/code/Magento/Eav/Test/Unit/Model/AttributeSetRepositoryTest.php index 1f8b53f8a70a1..ae93265dd4192 100644 --- a/app/code/Magento/Eav/Test/Unit/Model/AttributeSetRepositoryTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/AttributeSetRepositoryTest.php @@ -215,7 +215,7 @@ public function testGetList() $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->once())->method('getValue')->willReturn($entityTypeCode); From e9339ca5e929529a5bd4aaa4183d17683aeb9539 Mon Sep 17 00:00:00 2001 From: David Manners Date: Sat, 4 Nov 2017 14:22:18 +0000 Subject: [PATCH 7/7] Update the getField in the testGetList to be called twice --- .../Magento/Eav/Test/Unit/Model/AttributeSetRepositoryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Eav/Test/Unit/Model/AttributeSetRepositoryTest.php b/app/code/Magento/Eav/Test/Unit/Model/AttributeSetRepositoryTest.php index ae93265dd4192..fb4a0324b85af 100644 --- a/app/code/Magento/Eav/Test/Unit/Model/AttributeSetRepositoryTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/AttributeSetRepositoryTest.php @@ -217,7 +217,7 @@ public function testGetList() $filterMock = $this->getMock('\Magento\Framework\Api\Filter', [], [], '', false); $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(