Skip to content

Commit 34cf76d

Browse files
author
dnyomo
committed
Updated the default sort to check if the category id is passed as an array.
Reverted the tests back to check on products
1 parent c137e0e commit 34cf76d

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

app/code/Magento/CatalogGraphQl/DataProvider/Product/SearchCriteriaBuilder.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,13 @@ private function addDefaultSortOrder(SearchCriteriaInterface $searchCriteria, ar
212212
->create();
213213
} else {
214214
$categoryIdFilter = isset($args['filter']['category_id']) ? $args['filter']['category_id'] : false;
215-
if ($categoryIdFilter &&
216-
!is_array($categoryIdFilter[array_key_first($categoryIdFilter)]) ||
217-
count($categoryIdFilter[array_key_first($categoryIdFilter)]) <= 1
218-
) {
219-
$defaultSortOrder[] = $this->sortOrderBuilder
220-
->setField(EavAttributeInterface::POSITION)
221-
->setDirection(SortOrder::SORT_ASC)
222-
->create();
215+
if ($categoryIdFilter) {
216+
if (!is_array($categoryIdFilter[array_key_first($categoryIdFilter)]) || count($categoryIdFilter[array_key_first($categoryIdFilter)]) <= 1) {
217+
$defaultSortOrder[] = $this->sortOrderBuilder
218+
->setField(EavAttributeInterface::POSITION)
219+
->setDirection(SortOrder::SORT_ASC)
220+
->create();
221+
}
223222
}
224223
}
225224

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoriesQuery/CategoriesFilterTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ public function testQueryChildCategoriesWithProducts()
187187
$this->assertArrayHasKey('products', $baseCategory);
188188
//Check base category products
189189
$expectedBaseCategoryProducts = [
190+
['sku' => 'simple', 'name' => 'Simple Product'],
190191
['sku' => 'simple-4', 'name' => 'Simple Product Three'],
191192
['sku' => '12345', 'name' => 'Simple Product Two'],
192-
['sku' => 'simple', 'name' => 'Simple Product']
193193
];
194194
$this->assertCategoryProducts($baseCategory, $expectedBaseCategoryProducts);
195195
//Check base category children
@@ -297,8 +297,8 @@ public function testQueryCategoryWithDisabledChildren()
297297
$this->assertEquals('Its a description of Test Category 1.2', $firstChildCategory['description']);
298298

299299
$firstChildCategoryExpectedProducts = [
300-
['sku' => 'simple-4', 'name' => 'Simple Product Three'],
301-
['sku' => 'simple', 'name' => 'Simple Product']
300+
['sku' => 'simple', 'name' => 'Simple Product'],
301+
['sku' => 'simple-4', 'name' => 'Simple Product Three']
302302
];
303303
$this->assertCategoryProducts($firstChildCategory, $firstChildCategoryExpectedProducts);
304304
$firstChildCategoryChildren = [];

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoriesQuery/CategoryTreeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ public function testCategoryProducts()
453453
$this->assertAttributes($firstProduct);
454454
$this->assertWebsites($firstProductModel, $firstProduct['websites']);
455455
$this->assertEquals('Category 1', $firstProduct['categories'][0]['name']);
456-
$this->assertEquals('movable-position-2', $firstProduct['categories'][1]['url_path']);
456+
$this->assertEquals('category-1/category-1-1', $firstProduct['categories'][1]['url_path']);
457457
$this->assertCount(3, $firstProduct['categories']);
458458
}
459459

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryListTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ public function testQueryChildCategoriesWithProducts()
214214
$this->assertEquals('Category 1.2', $secondChildCategory['name']);
215215
$this->assertEquals('Its a description of Test Category 1.2', $secondChildCategory['description']);
216216
$firstChildCategoryExpectedProducts = [
217-
['sku' => 'simple-4', 'name' => 'Simple Product Three'],
218217
['sku' => 'simple', 'name' => 'Simple Product'],
218+
['sku' => 'simple-4', 'name' => 'Simple Product Three']
219219
];
220220
$this->assertCategoryProducts($secondChildCategory, $firstChildCategoryExpectedProducts);
221221
$firstChildCategoryChildren = [];
@@ -277,9 +277,9 @@ public function testQueryCategoryWithDisabledChildren()
277277
$this->assertArrayHasKey('products', $baseCategory);
278278
//Check base category products
279279
$expectedBaseCategoryProducts = [
280+
['sku' => 'simple', 'name' => 'Simple Product'],
280281
['sku' => 'simple-4', 'name' => 'Simple Product Three'],
281-
['sku' => '12345', 'name' => 'Simple Product Two'],
282-
['sku' => 'simple', 'name' => 'Simple Product']
282+
['sku' => '12345', 'name' => 'Simple Product Two']
283283
];
284284
$this->assertCategoryProducts($baseCategory, $expectedBaseCategoryProducts);
285285
//Check base category children
@@ -294,8 +294,8 @@ public function testQueryCategoryWithDisabledChildren()
294294
$this->assertEquals('Its a description of Test Category 1.2', $firstChildCategory['description']);
295295

296296
$firstChildCategoryExpectedProducts = [
297-
['sku' => 'simple-4', 'name' => 'Simple Product Three'],
298-
['sku' => 'simple', 'name' => 'Simple Product']
297+
['sku' => 'simple', 'name' => 'Simple Product'],
298+
['sku' => 'simple-4', 'name' => 'Simple Product Three']
299299
];
300300
$this->assertCategoryProducts($firstChildCategory, $firstChildCategoryExpectedProducts);
301301
$firstChildCategoryChildren = [];

0 commit comments

Comments
 (0)