Skip to content

Commit be5513f

Browse files
committed
Merge remote-tracking branch 'origin/AC-5984' into Hammer_Community_Backlog_06092022
2 parents 3ed00ff + 641e9cb commit be5513f

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

app/code/Magento/CatalogGraphQl/DataProvider/Product/LayeredNavigation/Builder/Category.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Framework\Api\Search\AggregationValueInterface;
1818
use Magento\Framework\Api\Search\BucketInterface;
1919
use Magento\Framework\App\ResourceConnection;
20+
use Magento\Framework\GraphQl\Query\Uid;
2021

2122
/**
2223
* Category layer builder
@@ -75,6 +76,9 @@ class Category implements LayerBuilderInterface
7576
*/
7677
private Aggregations\Category\IncludeDirectChildrenOnly $includeDirectChildrenOnly;
7778

79+
/** @var Uid */
80+
private Uid $uidEncoder;
81+
7882
/**
7983
* @param CategoryAttributeQuery $categoryAttributeQuery
8084
* @param CategoryAttributesMapper $attributesMapper
@@ -83,6 +87,7 @@ class Category implements LayerBuilderInterface
8387
* @param LayerFormatter $layerFormatter
8488
* @param Aggregations\Category\IncludeDirectChildrenOnly $includeDirectChildrenOnly
8589
* @param CollectionFactory $categoryCollectionFactory
90+
* @param Uid $uidEncoder
8691
*/
8792
public function __construct(
8893
CategoryAttributeQuery $categoryAttributeQuery,
@@ -91,7 +96,8 @@ public function __construct(
9196
ResourceConnection $resourceConnection,
9297
LayerFormatter $layerFormatter,
9398
Aggregations\Category\IncludeDirectChildrenOnly $includeDirectChildrenOnly,
94-
CollectionFactory $categoryCollectionFactory
99+
CollectionFactory $categoryCollectionFactory,
100+
Uid $uidEncoder
95101
) {
96102
$this->categoryAttributeQuery = $categoryAttributeQuery;
97103
$this->attributesMapper = $attributesMapper;
@@ -100,6 +106,7 @@ public function __construct(
100106
$this->layerFormatter = $layerFormatter;
101107
$this->includeDirectChildrenOnly = $includeDirectChildrenOnly;
102108
$this->categoryCollectionFactory = $categoryCollectionFactory;
109+
$this->uidEncoder = $uidEncoder;
103110
}
104111

105112
/**
@@ -155,7 +162,7 @@ function (AggregationValueInterface $value) {
155162
}
156163
$result['options'][] = $this->layerFormatter->buildItem(
157164
$categoryLabels[$categoryId] ?? $categoryId,
158-
$categoryId,
165+
$this->uidEncoder->encode((string) $categoryId),
159166
$value->getMetrics()['count']
160167
);
161168
}

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,30 @@
77

88
namespace Magento\GraphQl\Catalog;
99

10+
use Magento\Framework\GraphQl\Query\Uid;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use Magento\TestFramework\ObjectManager;
1013
use Magento\TestFramework\TestCase\GraphQlAbstract;
1114

1215
/**
1316
* Test of search by category ID aggregation.
1417
*/
1518
class ProductSearchCategoryAggregationsTest extends GraphQlAbstract
1619
{
20+
/** @var ObjectManager */
21+
private $objectManager;
22+
23+
/** @var Uid */
24+
private $uid;
25+
26+
/**
27+
* @inheritdoc
28+
*/
29+
protected function setUp(): void
30+
{
31+
$this->objectManager = Bootstrap::getObjectManager();
32+
$this->uid = $this->objectManager->get(Uid::class);
33+
}
1734
/**
1835
* Test category_id aggregation on filter by "eq" category ID condition.
1936
*
@@ -84,6 +101,7 @@ private function aggregationCategoryTesting(string $filterValue, string $include
84101
{
85102
$query = $this->getGraphQlQuery($filterValue, $includeDirectChildrenOnly);
86103
$result = $this->graphQlQuery($query);
104+
87105
$this->assertArrayNotHasKey('errors', $result);
88106
$this->assertArrayHasKey('aggregations', $result['products']);
89107
$categoryAggregation = array_filter(
@@ -99,7 +117,7 @@ function ($a) {
99117
foreach ($categoryAggregation['options'] as $option) {
100118
$this->assertNotEmpty($option['value']);
101119
$this->assertNotEmpty($option['label']);
102-
$categoryAggregationIdsLabel[(int)$option['value']] = $option['label'];
120+
$categoryAggregationIdsLabel[$this->uid->decode($option['value'])] = $option['label'];
103121
}
104122
return $categoryAggregationIdsLabel;
105123
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,7 @@ public function testFilterProductsForExactMatchingName()
16801680
'options' => [
16811681
[
16821682
'label' => 'Colorful Category',
1683-
'value' => '330',
1683+
'value' => 'MzMw',
16841684
'count' => 2,
16851685
],
16861686
],

0 commit comments

Comments
 (0)