From 7eb4af76dd5ea876b91e4c36cf639f58cd6e33bc Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Tue, 10 May 2016 18:05:38 +0300 Subject: [PATCH 01/11] MAGETWO-50882: [Stackexchange] Category getlist web api method incorrectly using getTree so all searchCriteria methods don't work --- .../Api/CategoryListiningInterface.php | 21 +++ .../Data/CategorySearchResultsInterface.php | 30 ++++ .../Catalog/Model/CategoryListining.php | 119 +++++++++++++++ .../Test/Unit/Model/CategoryListiningTest.php | 135 ++++++++++++++++++ .../Unit/Model/CategoryRepositoryTest.php | 46 ++---- app/code/Magento/Catalog/etc/di.xml | 2 + app/code/Magento/Catalog/etc/webapi.xml | 6 + .../Catalog/Api/CategoryListiningTest.php | 64 +++++++++ 8 files changed, 392 insertions(+), 31 deletions(-) create mode 100644 app/code/Magento/Catalog/Api/CategoryListiningInterface.php create mode 100644 app/code/Magento/Catalog/Api/Data/CategorySearchResultsInterface.php create mode 100644 app/code/Magento/Catalog/Model/CategoryListining.php create mode 100644 app/code/Magento/Catalog/Test/Unit/Model/CategoryListiningTest.php create mode 100644 dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListiningTest.php diff --git a/app/code/Magento/Catalog/Api/CategoryListiningInterface.php b/app/code/Magento/Catalog/Api/CategoryListiningInterface.php new file mode 100644 index 0000000000000..9722b0ae45b02 --- /dev/null +++ b/app/code/Magento/Catalog/Api/CategoryListiningInterface.php @@ -0,0 +1,21 @@ +categoryCollectionFactory = $categoryCollectionFactory; + $this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor; + $this->categorySearchResultsFactory = $categorySearchResultsFactory; + $this->categoryRepository = $categoryRepository; + } + + /** + * {@inheritdoc} + */ + public function getList(SearchCriteriaInterface $searchCriteria) + { + /** @var Collection $collection */ + $collection = $this->categoryCollectionFactory->create(); + $this->extensionAttributesJoinProcessor->process($collection); + + foreach ($searchCriteria->getFilterGroups() as $group) { + $this->addFilterGroupToCollection($group, $collection); + } + + /** @var SortOrder $sortOrder */ + $sortOrders = $searchCriteria->getSortOrders(); + if ($sortOrders) { + foreach ($sortOrders as $sortOrder) { + $collection->addOrder( + $sortOrder->getField(), + ($sortOrder->getDirection() === SortOrder::SORT_ASC) ? SortOrder::SORT_ASC : SortOrder::SORT_DESC + ); + } + } + + $collection->setCurPage($searchCriteria->getCurrentPage()); + $collection->setPageSize($searchCriteria->getPageSize()); + + $items = []; + foreach ($collection->getAllIds() as $id) { + $items[] = $this->categoryRepository->get($id); + } + + /** @var CategorySearchResultsInterface $searchResult */ + $searchResult = $this->categorySearchResultsFactory->create(); + $searchResult->setSearchCriteria($searchCriteria); + $searchResult->setItems($items); + $searchResult->setTotalCount($collection->getSize()); + return $searchResult; + } + + /** + * @param FilterGroup $filterGroup + * @param Collection $collection + * @return void + */ + protected function addFilterGroupToCollection(FilterGroup $filterGroup, Collection $collection) + { + $filters = $filterGroup->getFilters(); + if ($filters) { + $fields = []; + foreach ($filters as $filter) { + $conditionType = $filter->getConditionType() ? $filter->getConditionType() : 'eq'; + $fields[] = ['attribute' => $filter->getField(), $conditionType => $filter->getValue()]; + } + $collection->addFieldToFilter($fields); + } + } +} diff --git a/app/code/Magento/Catalog/Test/Unit/Model/CategoryListiningTest.php b/app/code/Magento/Catalog/Test/Unit/Model/CategoryListiningTest.php new file mode 100644 index 0000000000000..a34d695f7e9a5 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Unit/Model/CategoryListiningTest.php @@ -0,0 +1,135 @@ +categoryCollectionFactory = $this->getMockBuilder(CollectionFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->extensionAttributesJoinProcessor = $this->getMock(JoinProcessorInterface::class); + $this->categorySearchResultsFactory = $this->getMockBuilder(CategorySearchResultsInterfaceFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->categoryRepository = $this->getMock(CategoryRepositoryInterface::class); + + $this->model = (new ObjectManager($this))->getObject( + CategoryListining::class, + [ + 'categoryCollectionFactory' => $this->categoryCollectionFactory, + 'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessor, + 'categorySearchResultsFactory' => $this->categorySearchResultsFactory, + 'categoryRepository' => $this->categoryRepository, + ] + ); + } + + public function testGetList() + { + $fieldName = 'field_1'; + $value = 'value_1'; + $conditionType = 'eq'; + $currentPage = 2; + $pageSize = 1; + $totalCount = 2; + $categoryIdFirst = 1; + $categoryIdSecond = 2; + + $categoryFirst = $this->getMockBuilder(Category::class)->disableOriginalConstructor()->getMock(); + $categorySecond = $this->getMockBuilder(Category::class)->disableOriginalConstructor()->getMock(); + + $filter = $this->getMockBuilder(Filter::class)->disableOriginalConstructor()->getMock(); + $filter->expects($this->atLeastOnce())->method('getConditionType')->willReturn($conditionType); + $filter->expects($this->atLeastOnce())->method('getField')->willReturn($fieldName); + $filter->expects($this->once())->method('getValue')->willReturn($value); + + $filterGroup = $this->getMockBuilder(FilterGroup::class)->disableOriginalConstructor()->getMock(); + $filterGroup->expects($this->once())->method('getFilters')->willReturn([$filter]); + + $sortOrder = $this->getMockBuilder(SortOrder::class)->disableOriginalConstructor()->getMock(); + $sortOrder->expects($this->once())->method('getField')->willReturn($fieldName); + $sortOrder->expects($this->once())->method('getDirection')->willReturn(SortOrder::SORT_ASC); + + /** @var SearchCriteriaInterface|\PHPUnit_Framework_MockObject_MockObject $searchCriteria */ + $searchCriteria = $this->getMock(SearchCriteriaInterface::class); + $searchCriteria->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroup]); + $searchCriteria->expects($this->once())->method('getCurrentPage')->willReturn($currentPage); + $searchCriteria->expects($this->once())->method('getPageSize')->willReturn($pageSize); + $searchCriteria->expects($this->once())->method('getSortOrders')->willReturn([$sortOrder]); + + $collection = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock(); + $collection->expects($this->once()) + ->method('addFieldToFilter') + ->with([['attribute' => $fieldName, $conditionType => $value]]); + $collection->expects($this->once())->method('addOrder')->with($fieldName, SortOrder::SORT_ASC); + $collection->expects($this->once())->method('setCurPage')->with($currentPage); + $collection->expects($this->once())->method('setPageSize')->with($pageSize); + $collection->expects($this->once())->method('getSize')->willReturn($totalCount); + $collection->expects($this->once())->method('getAllIds')->willReturn([$categoryIdFirst, $categoryIdSecond]); + + $searchResult = $this->getMock(CategorySearchResultsInterface::class); + $searchResult->expects($this->once())->method('setSearchCriteria')->with($searchCriteria); + $searchResult->expects($this->once())->method('setItems')->with([$categoryFirst, $categorySecond]); + $searchResult->expects($this->once())->method('setTotalCount')->with($totalCount); + + $this->categoryRepository->expects($this->exactly(2)) + ->method('get') + ->willReturnMap([ + [$categoryIdFirst, $categoryFirst], + [$categoryIdSecond, $categorySecond], + ]) + ->willReturn($categoryFirst); + + $this->categorySearchResultsFactory->expects($this->once())->method('create')->willReturn($searchResult); + $this->categoryCollectionFactory->expects($this->once())->method('create')->willReturn($collection); + $this->extensionAttributesJoinProcessor->expects($this->once())->method('process')->with($collection); + + $this->assertEquals($searchResult, $this->model->getList($searchCriteria)); + } +} diff --git a/app/code/Magento/Catalog/Test/Unit/Model/CategoryRepositoryTest.php b/app/code/Magento/Catalog/Test/Unit/Model/CategoryRepositoryTest.php index 04b6d809f7f44..d94435d21fd52 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/CategoryRepositoryTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/CategoryRepositoryTest.php @@ -5,10 +5,15 @@ */ namespace Magento\Catalog\Test\Unit\Model; +use Magento\Catalog\Model\Category; +use Magento\Catalog\Model\CategoryRepository; +use Magento\Catalog\Model\ResourceModel\Category\Collection; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; + class CategoryRepositoryTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Catalog\Model\CategoryRepository + * @var CategoryRepository */ protected $model; @@ -88,21 +93,16 @@ protected function setUp() ->with(\Magento\Catalog\Api\Data\CategoryInterface::class) ->willReturn($metadataMock); - $this->model = new \Magento\Catalog\Model\CategoryRepository( - $this->categoryFactoryMock, - $this->categoryResourceMock, - $this->storeManagerMock + $this->model = (new ObjectManager($this))->getObject( + CategoryRepository::class, + [ + 'categoryFactory' => $this->categoryFactoryMock, + 'categoryResource' => $this->categoryResourceMock, + 'storeManager' => $this->storeManagerMock, + 'metadataPool' => $this->metadataPoolMock, + 'extensibleDataObjectConverter' => $this->extensibleDataObjectConverterMock, + ] ); - - $this->setProperties($this->model, [ - 'metadataPool' => $this->metadataPoolMock - ]); - - // Todo: \Magento\Framework\TestFramework\Unit\Helper\ObjectManager to do this automatically (MAGETWO-49793) - $reflection = new \ReflectionClass(get_class($this->model)); - $reflectionProperty = $reflection->getProperty('extensibleDataObjectConverter'); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue($this->model, $this->extensibleDataObjectConverterMock); } public function testGet() @@ -371,20 +371,4 @@ public function testDeleteByIdentifierWithException() ); $this->model->deleteByIdentifier($categoryId); } - - /** - * @param $object - * @param array $properties - */ - private function setProperties($object, $properties = []) - { - $reflectionClass = new \ReflectionClass(get_class($object)); - foreach ($properties as $key => $value) { - if ($reflectionClass->hasProperty($key)) { - $reflectionProperty = $reflectionClass->getProperty($key); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue($object, $value); - } - } - } } diff --git a/app/code/Magento/Catalog/etc/di.xml b/app/code/Magento/Catalog/etc/di.xml index 92f86792a83fa..cc8c1f15dd080 100644 --- a/app/code/Magento/Catalog/etc/di.xml +++ b/app/code/Magento/Catalog/etc/di.xml @@ -43,6 +43,8 @@ + + diff --git a/app/code/Magento/Catalog/etc/webapi.xml b/app/code/Magento/Catalog/etc/webapi.xml index a8dc6ead7975f..496a6175a334b 100644 --- a/app/code/Magento/Catalog/etc/webapi.xml +++ b/app/code/Magento/Catalog/etc/webapi.xml @@ -283,6 +283,12 @@ + + + + + + diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListiningTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListiningTest.php new file mode 100644 index 0000000000000..871a3e49fe1bd --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListiningTest.php @@ -0,0 +1,64 @@ + [ + 'filter_groups' => [ + [ + 'filters' => [ + [ + 'field' => 'name', + 'value' => 'Category 1', + 'condition_type' => 'eq', + ], + ], + ], + ], + 'current_page' => 1, + 'page_size' => 2, + ], + ]; + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($searchCriteria), + 'httpMethod' => Request::HTTP_METHOD_GET, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'operation' => self::SERVICE_NAME . 'GetList', + ], + ]; + + $response = $this->_webApiCall($serviceInfo, $searchCriteria); + + $this->assertArrayHasKey('search_criteria', $response); + $this->assertArrayHasKey('total_count', $response); + $this->assertArrayHasKey('items', $response); + + $this->assertEquals($searchCriteria['searchCriteria'], $response['search_criteria']); + $this->assertTrue($response['total_count'] > 0); + $this->assertTrue(count($response['items']) > 0); + + $this->assertNotNull($response['items'][0]['name']); + $this->assertEquals('Category 1', $response['items'][0]['name']); + } +} From 65a1cc0470f3d3f528d0703cf2581d7bc2ba66b6 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Tue, 10 May 2016 18:16:21 +0300 Subject: [PATCH 02/11] MAGETWO-50882: [Stackexchange] Category getlist web api method incorrectly using getTree so all searchCriteria methods don't work -- fix static tests --- .../Magento/Catalog/Test/Unit/Model/CategoryListiningTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/CategoryListiningTest.php b/app/code/Magento/Catalog/Test/Unit/Model/CategoryListiningTest.php index a34d695f7e9a5..abcdd96d1388c 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/CategoryListiningTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/CategoryListiningTest.php @@ -19,6 +19,9 @@ use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Catalog\Api\Data\CategorySearchResultsInterfaceFactory; +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class CategoryListiningTest extends \PHPUnit_Framework_TestCase { /** From d5fd81f822dd680f2a7b036d0b622140edd1db92 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Tue, 17 May 2016 12:32:22 +0300 Subject: [PATCH 03/11] MAGETWO-50882: [Stackexchange] Category getlist web api method incorrectly using getTree so all searchCriteria methods don't work -- fixes after merge --- app/code/Magento/Catalog/etc/di.xml | 30 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/Catalog/etc/di.xml b/app/code/Magento/Catalog/etc/di.xml index 46e10cc89eefa..393c9b64b751e 100644 --- a/app/code/Magento/Catalog/etc/di.xml +++ b/app/code/Magento/Catalog/etc/di.xml @@ -99,6 +99,11 @@ Magento\Catalog\Api\ProductRepositoryInterface\Proxy + + + Magento\Backend\Model\Session\Proxy + + Magento\Catalog\Model\Product\Attribute\Source\Status\Proxy @@ -572,6 +577,14 @@ Magento\Store\Model\StoreScopeProvider + + catalog_category_entity + catalog_category + entity_id + + Magento\Store\Model\StoreScopeProvider + + @@ -714,19 +727,12 @@ Magento\Catalog\Model\ResourceModel\AttributePersistor - + - - - - Magento\Catalog\Model\ResourceModel\CreateHandler - Magento\Catalog\Model\ResourceModel\UpdateHandler - - - Magento\Catalog\Model\ResourceModel\CreateHandler - Magento\Catalog\Model\ResourceModel\UpdateHandler - - + + Magento\Framework\EntityManager\AbstractModelHydrator + Magento\Framework\EntityManager\AbstractModelHydrator + Magento\Framework\EntityManager\AbstractModelHydrator From ebf49d5e7ebdee1c50b7cd0ceb9abb0f3773fff3 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Tue, 17 May 2016 13:33:05 +0300 Subject: [PATCH 04/11] MAGETWO-50882: [Stackexchange] Category getlist web api method incorrectly using getTree so all searchCriteria methods don't work -- fixes api tests --- .../testsuite/Magento/Catalog/Api/CategoryListiningTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListiningTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListiningTest.php index 871a3e49fe1bd..9f22b8ddce7a5 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListiningTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListiningTest.php @@ -15,7 +15,7 @@ class CategoryListiningTest extends WebapiAbstract const SERVICE_NAME = 'catalogCategoryListiningV1'; /** - * @magentoApiDataFixture Magento/Catalog/_files/category.php + * @magentoApiDataFixture Magento/Catalog/_files/category_tree.php */ public function testGetList() { From 4e16823a368ab0c2380748bdad78ba2758865e56 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Thu, 2 Jun 2016 13:07:45 +0300 Subject: [PATCH 05/11] MAGETWO-50882: [Stackexchange] Category getlist web api method incorrectly using getTree so all searchCriteria methods don't work -- fix misprint in api interface name --- ...ryListiningInterface.php => CategoryListInterface.php} | 2 +- .../Model/{CategoryListining.php => CategoryList.php} | 4 ++-- .../{CategoryListiningTest.php => CategoryListTest.php} | 8 ++++---- app/code/Magento/Catalog/etc/di.xml | 2 +- app/code/Magento/Catalog/etc/webapi.xml | 2 +- .../Magento/Catalog/Api/CategoryListiningTest.php | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) rename app/code/Magento/Catalog/Api/{CategoryListiningInterface.php => CategoryListInterface.php} (92%) rename app/code/Magento/Catalog/Model/{CategoryListining.php => CategoryList.php} (97%) rename app/code/Magento/Catalog/Test/Unit/Model/{CategoryListiningTest.php => CategoryListTest.php} (97%) diff --git a/app/code/Magento/Catalog/Api/CategoryListiningInterface.php b/app/code/Magento/Catalog/Api/CategoryListInterface.php similarity index 92% rename from app/code/Magento/Catalog/Api/CategoryListiningInterface.php rename to app/code/Magento/Catalog/Api/CategoryListInterface.php index 9722b0ae45b02..db0cfaf911d40 100644 --- a/app/code/Magento/Catalog/Api/CategoryListiningInterface.php +++ b/app/code/Magento/Catalog/Api/CategoryListInterface.php @@ -9,7 +9,7 @@ /** * @api */ -interface CategoryListiningInterface +interface CategoryListInterface { /** * Get category list diff --git a/app/code/Magento/Catalog/Model/CategoryListining.php b/app/code/Magento/Catalog/Model/CategoryList.php similarity index 97% rename from app/code/Magento/Catalog/Model/CategoryListining.php rename to app/code/Magento/Catalog/Model/CategoryList.php index 4d20561ab3229..cb7e3cadc1235 100644 --- a/app/code/Magento/Catalog/Model/CategoryListining.php +++ b/app/code/Magento/Catalog/Model/CategoryList.php @@ -7,7 +7,7 @@ namespace Magento\Catalog\Model; -use Magento\Catalog\Api\CategoryListiningInterface; +use Magento\Catalog\Api\CategoryListInterface; use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Catalog\Api\Data\CategorySearchResultsInterface; use Magento\Catalog\Api\Data\CategorySearchResultsInterfaceFactory; @@ -19,7 +19,7 @@ use Magento\Framework\Api\SortOrder; use Magento\Framework\App\ObjectManager; -class CategoryListining implements CategoryListiningInterface +class CategoryList implements CategoryListInterface { /** * @var CollectionFactory diff --git a/app/code/Magento/Catalog/Test/Unit/Model/CategoryListiningTest.php b/app/code/Magento/Catalog/Test/Unit/Model/CategoryListTest.php similarity index 97% rename from app/code/Magento/Catalog/Test/Unit/Model/CategoryListiningTest.php rename to app/code/Magento/Catalog/Test/Unit/Model/CategoryListTest.php index abcdd96d1388c..4f72f43485bc7 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/CategoryListiningTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/CategoryListTest.php @@ -8,7 +8,7 @@ use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Catalog\Api\Data\CategorySearchResultsInterface; use Magento\Catalog\Model\Category; -use Magento\Catalog\Model\CategoryListining; +use Magento\Catalog\Model\CategoryList; use Magento\Catalog\Model\ResourceModel\Category\Collection; use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface; use Magento\Framework\Api\Filter; @@ -22,10 +22,10 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class CategoryListiningTest extends \PHPUnit_Framework_TestCase +class CategoryListTest extends \PHPUnit_Framework_TestCase { /** - * @var CategoryListining + * @var CategoryList */ protected $model; @@ -63,7 +63,7 @@ protected function setUp() $this->categoryRepository = $this->getMock(CategoryRepositoryInterface::class); $this->model = (new ObjectManager($this))->getObject( - CategoryListining::class, + CategoryList::class, [ 'categoryCollectionFactory' => $this->categoryCollectionFactory, 'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessor, diff --git a/app/code/Magento/Catalog/etc/di.xml b/app/code/Magento/Catalog/etc/di.xml index 393c9b64b751e..c532abaf68307 100644 --- a/app/code/Magento/Catalog/etc/di.xml +++ b/app/code/Magento/Catalog/etc/di.xml @@ -44,7 +44,7 @@ - + diff --git a/app/code/Magento/Catalog/etc/webapi.xml b/app/code/Magento/Catalog/etc/webapi.xml index 496a6175a334b..99670c347a89b 100644 --- a/app/code/Magento/Catalog/etc/webapi.xml +++ b/app/code/Magento/Catalog/etc/webapi.xml @@ -284,7 +284,7 @@ - + diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListiningTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListiningTest.php index 9f22b8ddce7a5..830e2a7d122ac 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListiningTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListiningTest.php @@ -9,10 +9,10 @@ use Magento\Framework\Webapi\Rest\Request; use Magento\TestFramework\TestCase\WebapiAbstract; -class CategoryListiningTest extends WebapiAbstract +class CategoryListTest extends WebapiAbstract { const RESOURCE_PATH = '/V1/categories/list'; - const SERVICE_NAME = 'catalogCategoryListiningV1'; + const SERVICE_NAME = 'catalogCategoryListV1'; /** * @magentoApiDataFixture Magento/Catalog/_files/category_tree.php From df5f762cf15794e5aa4566240040814cbfc73c66 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Thu, 2 Jun 2016 13:18:15 +0300 Subject: [PATCH 06/11] MAGETWO-50882: [Stackexchange] Category getlist web api method incorrectly using getTree so all searchCriteria methods don't work -- fix misprint in api interface name --- .../Api/{CategoryListiningTest.php => CategoryListTest.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dev/tests/api-functional/testsuite/Magento/Catalog/Api/{CategoryListiningTest.php => CategoryListTest.php} (100%) diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListiningTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListTest.php similarity index 100% rename from dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListiningTest.php rename to dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListTest.php From 63cc19ee40a64e012fbad45679202ea21f989869 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Tue, 7 Jun 2016 16:16:48 +0300 Subject: [PATCH 07/11] MAGETWO-53826: Error occurs when redirecting a search term to a URL containing layered navigation parameters --- .../CatalogSearch/Controller/Result/Index.php | 5 +++-- .../CatalogSearch/Controller/ResultTest.php | 22 +++++++++++++++++++ .../CatalogSearch/_files/query_redirect.php | 17 ++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/CatalogSearch/_files/query_redirect.php diff --git a/app/code/Magento/CatalogSearch/Controller/Result/Index.php b/app/code/Magento/CatalogSearch/Controller/Result/Index.php index f9866aaeff36b..394c3d0bf3687 100644 --- a/app/code/Magento/CatalogSearch/Controller/Result/Index.php +++ b/app/code/Magento/CatalogSearch/Controller/Result/Index.php @@ -79,8 +79,9 @@ public function execute() } else { $query->saveIncrementalPopularity(); - if ($query->getRedirect()) { - $this->getResponse()->setRedirect($query->getRedirect()); + $redirect = $query->getRedirect(); + if ($redirect && $this->_url->getCurrentUrl() !== $redirect) { + $this->getResponse()->setRedirect($redirect); return; } } diff --git a/dev/tests/integration/testsuite/Magento/CatalogSearch/Controller/ResultTest.php b/dev/tests/integration/testsuite/Magento/CatalogSearch/Controller/ResultTest.php index 0bf8a0ff2ca51..97026b5e229ea 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogSearch/Controller/ResultTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogSearch/Controller/ResultTest.php @@ -37,4 +37,26 @@ public function testIndexActionXSSQueryVerification() $this->assertNotContains($data, $responseBody); $this->assertContains(htmlspecialchars($data, ENT_COMPAT, 'UTF-8', false), $responseBody); } + + /** + * @magentoDataFixture Magento/CatalogSearch/_files/query_redirect.php + */ + public function testRedirect() + { + $this->dispatch('/catalogsearch/result/?q=query_text'); + $responseBody = $this->getResponse(); + + $this->assertTrue($responseBody->isRedirect()); + } + + /** + * @magentoDataFixture Magento/CatalogSearch/_files/query_redirect.php + */ + public function testNoRedirectIfCurrentUrlAndRedirectTermAreSame() + { + $this->dispatch('/catalogsearch/result/?q=query_text&cat=41'); + $responseBody = $this->getResponse(); + + $this->assertFalse($responseBody->isRedirect()); + } } diff --git a/dev/tests/integration/testsuite/Magento/CatalogSearch/_files/query_redirect.php b/dev/tests/integration/testsuite/Magento/CatalogSearch/_files/query_redirect.php new file mode 100644 index 0000000000000..0dcada80c2959 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogSearch/_files/query_redirect.php @@ -0,0 +1,17 @@ +get(UrlInterface::class); + +$query->setRedirect($url->getCurrentUrl() . 'catalogsearch/result/?q=query_text&cat=41') + ->save(); From 5fae309e4afef5fbae7f30f45e57eac85df4e4b4 Mon Sep 17 00:00:00 2001 From: Anton Ohorodnyk Date: Tue, 14 Jun 2016 15:54:07 +0300 Subject: [PATCH 08/11] MAGETWO-53445: [Github] "Catalog Products List" includes "Out of Stock" products when "Quantity is In Stock" is a required condition of the widget and the products are given the quantity "Out of Stock" from within admin #4108 --- app/code/Magento/CatalogWidget/Model/Rule/Condition/Combine.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/CatalogWidget/Model/Rule/Condition/Combine.php b/app/code/Magento/CatalogWidget/Model/Rule/Condition/Combine.php index 386e77580fa4a..23c769bd290db 100644 --- a/app/code/Magento/CatalogWidget/Model/Rule/Condition/Combine.php +++ b/app/code/Magento/CatalogWidget/Model/Rule/Condition/Combine.php @@ -44,6 +44,8 @@ public function getNewChildSelectOptions() $productAttributes = $this->productFactory->create()->loadAttributeOptions()->getAttributeOption(); $attributes = []; foreach ($productAttributes as $code => $label) { + $excludeAttributes = ['quantity_and_stock_status']; + if (!in_array($code, $excludeAttributes)) $attributes[] = [ 'value' => 'Magento\CatalogWidget\Model\Rule\Condition\Product|' . $code, 'label' => $label, From 7b168f9c60732d45df085e6769e567270f05c63a Mon Sep 17 00:00:00 2001 From: Anton Ohorodnyk Date: Wed, 15 Jun 2016 16:12:43 +0300 Subject: [PATCH 09/11] MAGETWO-53445: [Github] "Catalog Products List" includes "Out of Stock" products when "Quantity is In Stock" is a required condition of the widget and the products are given the quantity "Out of Stock" from within admin #4108 - Extracted variable to di.xml --- .../Model/Rule/Condition/Combine.php | 22 +++++++++++++------ app/code/Magento/CatalogWidget/etc/di.xml | 16 ++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 app/code/Magento/CatalogWidget/etc/di.xml diff --git a/app/code/Magento/CatalogWidget/Model/Rule/Condition/Combine.php b/app/code/Magento/CatalogWidget/Model/Rule/Condition/Combine.php index 23c769bd290db..0672ff9a47840 100644 --- a/app/code/Magento/CatalogWidget/Model/Rule/Condition/Combine.php +++ b/app/code/Magento/CatalogWidget/Model/Rule/Condition/Combine.php @@ -21,19 +21,27 @@ class Combine extends \Magento\Rule\Model\Condition\Combine */ protected $elementName = 'parameters'; + /** + * @var array + */ + private $excludedAttributes; + /** * @param \Magento\Rule\Model\Condition\Context $context * @param \Magento\CatalogWidget\Model\Rule\Condition\ProductFactory $conditionFactory * @param array $data + * @param array $excludedAttributes */ public function __construct( \Magento\Rule\Model\Condition\Context $context, \Magento\CatalogWidget\Model\Rule\Condition\ProductFactory $conditionFactory, - array $data = [] + array $data = [], + array $excludedAttributes = [] ) { $this->productFactory = $conditionFactory; parent::__construct($context, $data); $this->setType('Magento\CatalogWidget\Model\Rule\Condition\Combine'); + $this->excludedAttributes = $excludedAttributes; } /** @@ -44,12 +52,12 @@ public function getNewChildSelectOptions() $productAttributes = $this->productFactory->create()->loadAttributeOptions()->getAttributeOption(); $attributes = []; foreach ($productAttributes as $code => $label) { - $excludeAttributes = ['quantity_and_stock_status']; - if (!in_array($code, $excludeAttributes)) - $attributes[] = [ - 'value' => 'Magento\CatalogWidget\Model\Rule\Condition\Product|' . $code, - 'label' => $label, - ]; + if (!in_array($code, $this->excludedAttributes)) { + $attributes[] = [ + 'value' => 'Magento\CatalogWidget\Model\Rule\Condition\Product|' . $code, + 'label' => $label, + ]; + } } $conditions = parent::getNewChildSelectOptions(); $conditions = array_merge_recursive( diff --git a/app/code/Magento/CatalogWidget/etc/di.xml b/app/code/Magento/CatalogWidget/etc/di.xml new file mode 100644 index 0000000000000..625bcf58c5ca7 --- /dev/null +++ b/app/code/Magento/CatalogWidget/etc/di.xml @@ -0,0 +1,16 @@ + + + + + + + quantity_and_stock_status + + + + From d709366e6cf0f42a56fc26dfea8fd58c1aa62f53 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Thu, 28 Jul 2016 14:54:03 +0300 Subject: [PATCH 10/11] MAGETWO-54729: Deliver fixed issues - Fixes after PR review --- .../Magento/Catalog/Api/CategoryListInterface.php | 1 - .../Api/Data/CategorySearchResultsInterface.php | 1 - app/code/Magento/Catalog/Model/CategoryList.php | 12 ++++++------ .../Test/Unit/Model/Rule/Condition/CombineTest.php | 2 ++ .../Magento/Catalog/Api/CategoryListTest.php | 1 - 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Catalog/Api/CategoryListInterface.php b/app/code/Magento/Catalog/Api/CategoryListInterface.php index db0cfaf911d40..67a4ba5db000e 100644 --- a/app/code/Magento/Catalog/Api/CategoryListInterface.php +++ b/app/code/Magento/Catalog/Api/CategoryListInterface.php @@ -1,6 +1,5 @@ disableOriginalConstructor() ->getMock(); $arguments['conditionFactory'] = $this->conditionFactory; + $arguments['excludedAttributes'] = ['excluded_attribute']; $this->condition = $objectManagerHelper->getObject( 'Magento\CatalogWidget\Model\Rule\Condition\Combine', @@ -56,6 +57,7 @@ public function testGetNewChildSelectOptions() $attributeOptions = [ 'sku' => 'SKU', 'category' => 'Category', + 'excluded_attribute' => 'Excluded attribute', ]; $productCondition = $this->getMockBuilder('\Magento\CatalogWidget\Model\Rule\Condition\Product') ->setMethods(['loadAttributeOptions', 'getAttributeOption']) diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListTest.php index 830e2a7d122ac..e7d53148d8454 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListTest.php @@ -1,6 +1,5 @@ Date: Thu, 28 Jul 2016 15:07:10 +0300 Subject: [PATCH 11/11] MAGETWO-54729: Deliver fixed issues - Fixes after PR review --- app/code/Magento/Catalog/Model/CategoryList.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/CategoryList.php b/app/code/Magento/Catalog/Model/CategoryList.php index 18b384a214d31..b739c5bf46354 100644 --- a/app/code/Magento/Catalog/Model/CategoryList.php +++ b/app/code/Magento/Catalog/Model/CategoryList.php @@ -104,7 +104,7 @@ public function getList(SearchCriteriaInterface $searchCriteria) * @param Collection $collection * @return void */ - protected function addFilterGroupToCollection(FilterGroup $filterGroup, Collection $collection) + private function addFilterGroupToCollection(FilterGroup $filterGroup, Collection $collection) { $filters = $filterGroup->getFilters(); if ($filters) {