Skip to content

Commit 857a53a

Browse files
authored
Pwa 2948::Console error on accessing different filters, venia page also shows error toast. (#30)
* PWA-2948::Console error on accessing different filters, venia page also shows error toast. * PWA-2948::Console error on accessing different filters, venia page also shows error toast. * PWA-2948::Changed value of category_uid from category_id to uid * PWA-2948::Updated the class name from Category to CatrgoryUidUpdate
1 parent 96c5f5f commit 857a53a

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogGraphQlAux\Plugin;
9+
10+
use Magento\CatalogGraphQl\DataProvider\Product\LayeredNavigation\Formatter\LayerFormatter;
11+
use Magento\CatalogGraphQl\DataProvider\Product\LayeredNavigation\Builder\Category;
12+
use Magento\Framework\GraphQl\Query\Uid;
13+
14+
class CategoryUidUpdate
15+
{
16+
/** @var Uid */
17+
private Uid $uidEncoder;
18+
19+
/**
20+
* @var LayerFormatter
21+
*/
22+
private LayerFormatter $layerFormatter;
23+
24+
/**
25+
* @param LayerFormatter $layerFormatter
26+
* @param Uid $uidEncoder
27+
*/
28+
public function __construct(
29+
LayerFormatter $layerFormatter,
30+
Uid $uidEncoder
31+
) {
32+
$this->layerFormatter = $layerFormatter;
33+
$this->uidEncoder = $uidEncoder;
34+
}
35+
36+
/**
37+
* Plugin to update the category_id in value into category_uid
38+
*
39+
* @param Category $subject
40+
* @param array $result
41+
* @return array
42+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
43+
*/
44+
public function afterBuild(
45+
Category $subject,
46+
array $result
47+
): array {
48+
foreach ($result as $key => $option) {
49+
if ($option['attribute_code'] == 'category_uid') {
50+
foreach ($option['options'] as $label => $value) {
51+
$result[$key]['options'][$label]['value'] = $this->uidEncoder->encode((string) $value['value']);
52+
}
53+
}
54+
}
55+
56+
return $result;
57+
}
58+
}

CatalogGraphQlAux/etc/graphql/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
<type name="Magento\CatalogGraphQl\DataProvider\Product\LayeredNavigation\Builder\Price">
2020
<plugin name="price-add-position" type="Magento\CatalogGraphQlAux\Plugin\Price"/>
2121
</type>
22+
23+
<type name="Magento\CatalogGraphQl\DataProvider\Product\LayeredNavigation\Builder\Category">
24+
<plugin name="category-uid-update" type="Magento\CatalogGraphQlAux\Plugin\CategoryUidUpdate"/>
25+
</type>
26+
2227
<type name="Magento\CatalogGraphQl\Model\Resolver\Category\SortFields">
2328
<plugin name="sort-fields-label-by-store" type="Magento\CatalogGraphQlAux\Plugin\Model\Resolver\Category\SortFields"/>
2429
</type>

0 commit comments

Comments
 (0)