Skip to content

Commit dc88301

Browse files
committed
MC-42795: GraphQl products query layered navigation filters return incorrect child categories list
1 parent ad281b2 commit dc88301

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

app/code/Magento/CatalogGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ type Products @doc(description: "The Products object is the top-level object ret
320320
page_info: SearchResultPageInfo @doc(description: "An object that includes the page_info and currentPage values specified in the query.")
321321
total_count: Int @doc(description: "The number of products that are marked as visible. By default, in complex products, parent products are visible, but their child products are not.")
322322
filters: [LayerFilter] @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\LayerFilters") @doc(description: "Layered navigation filters array.") @deprecated(reason: "Use aggregations instead")
323-
aggregations (filter: AggregationsFilterInput): [Aggregation] @doc(description: "Layered navigation aggregations.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Aggregations")
323+
aggregations (filter: AggregationsFilterInput): [Aggregation] @doc(description: "Layered navigation aggregations with filters.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Aggregations")
324324
sort_fields: SortFields @doc(description: "An object that includes the default sort field and all available sort fields.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\SortFields")
325325
}
326326

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ public function testAggregationEqCategory()
2424
{
2525
$filterValue = '{category_id: {eq: "2"}}';
2626
$categoryAggregation = $this->aggregationCategoryTesting($filterValue, "true");
27-
$this->assertEquals(4, $categoryAggregation['count']);
2827
$expectedOptions = $this->getCategoryTwoOptions();
29-
$this->assertEquals($expectedOptions, $categoryAggregation['options']);
28+
$this->assertEquals($expectedOptions, $categoryAggregation);
3029
}
3130

3231
/**
@@ -38,9 +37,8 @@ public function testAggregationInCategory()
3837
{
3938
$filterValue = '{category_id: {in: ["3","2"]}}';
4039
$categoryAggregation = $this->aggregationCategoryTesting($filterValue, "true");
41-
$this->assertEquals(6, $categoryAggregation['count']);
42-
$expectedOptions = array_merge($this->getCategoryThreeOptions(), $this->getCategoryTwoOptions());
43-
$this->assertEquals($expectedOptions, $categoryAggregation['options']);
40+
$expectedOptions = $this->getCategoryThreeOptions() + $this->getCategoryTwoOptions();
41+
$this->assertEquals($expectedOptions, $categoryAggregation);
4442
}
4543

4644
/**
@@ -63,7 +61,13 @@ function ($a) {
6361
$this->assertNotEmpty($categoryAggregation);
6462
$categoryAggregation = reset($categoryAggregation);
6563
$this->assertEquals('Category', $categoryAggregation['label']);
66-
return $categoryAggregation;
64+
$categoryAggregationIdsLabel = [];
65+
foreach ($categoryAggregation['options'] as $option) {
66+
$this->assertNotEmpty($option['value']);
67+
$this->assertNotEmpty($option['label']);
68+
$categoryAggregationIdsLabel[(int)$option['value']] = $option['label'];
69+
}
70+
return $categoryAggregationIdsLabel;
6771
}
6872

6973
/**
@@ -74,10 +78,10 @@ function ($a) {
7478
private function getCategoryTwoOptions(): array
7579
{
7680
return [
77-
['label' => 'Category 1', 'value'=> '3', 'count' => '3'],
78-
['label' => 'Movable Position 2', 'value'=> '10', 'count' => '1'],
79-
['label' => 'Movable Position 3', 'value'=> '11', 'count' => '1'],
80-
['label' => 'Category 12', 'value'=> '12', 'count' => '1']
81+
3 => 'Category 1',
82+
10 => 'Movable Position 2',
83+
11 => 'Movable Position 3',
84+
12 => 'Category 12'
8185
];
8286
}
8387

@@ -89,8 +93,8 @@ private function getCategoryTwoOptions(): array
8993
private function getCategoryThreeOptions(): array
9094
{
9195
return [
92-
['label' => 'Category 1.1', 'value'=> '4', 'count' => '2'],
93-
['label' => 'Category 1.2', 'value'=> '13', 'count' => '2']
96+
4 => 'Category 1.1',
97+
13 => 'Category 1.2'
9498
];
9599
}
96100

0 commit comments

Comments
 (0)