Skip to content

Commit e7eb9b9

Browse files
authored
[PWA-2499] Browser Reload on any Category load all products from default category (#18)
* Add support for UID field * Add null guards to uid encoding
1 parent af7f3a0 commit e7eb9b9

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Model/Computed/PageInfo.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Magento\UpwardConnector\Model\Computed;
1010

11+
use Magento\Framework\GraphQl\Query\Uid;
1112
use Magento\Framework\Serialize\Serializer\Json;
1213
use Magento\Store\Model\StoreManagerInterface;
1314
use Magento\Upward\Definition;
@@ -30,6 +31,9 @@ class PageInfo implements ComputedInterface
3031
/** @var \Magento\UrlRewriteGraphQl\Model\DataProvider\EntityDataProviderComposite */
3132
private $entityDataProviderComposite;
3233

34+
/** @var \Magento\Framework\GraphQl\Query\Uid */
35+
private $uid;
36+
3337
/**
3438
* @param \Magento\UpwardConnector\Model\PageType $pageTypeResolver
3539
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
@@ -40,12 +44,14 @@ public function __construct(
4044
PageType $pageTypeResolver,
4145
StoreManagerInterface $storeManager,
4246
Json $json,
43-
EntityDataProviderComposite $entityDataProviderComposite
47+
EntityDataProviderComposite $entityDataProviderComposite,
48+
Uid $uid
4449
) {
4550
$this->pageTypeResolver = $pageTypeResolver;
4651
$this->storeManager = $storeManager;
4752
$this->json = $json;
4853
$this->entityDataProviderComposite = $entityDataProviderComposite;
54+
$this->uid = $uid;
4955
}
5056

5157
/**
@@ -131,7 +137,7 @@ public function isPageInfoComplete($pageInfo, $additionalMap): bool
131137
{
132138
$pageInfoHasAllData = true;
133139
if ($additionalMap) {
134-
foreach($additionalMap as $key) {
140+
foreach ($additionalMap as $key) {
135141
if (!isset($pageInfo[$key])) {
136142
$pageInfoHasAllData = false;
137143

@@ -145,7 +151,8 @@ public function isPageInfoComplete($pageInfo, $additionalMap): bool
145151

146152
/**
147153
* @param array $data
148-
* @param array{type: string, fetch: string}|bool $map
154+
* @param array|bool $map
155+
* @param string $type
149156
*
150157
* @return array
151158
*/
@@ -156,7 +163,7 @@ public function filterData($data, $map, $type)
156163
}
157164

158165
$result = [];
159-
foreach($map as $valueKey) {
166+
foreach ($map as $valueKey) {
160167
$result[$valueKey] = $this->getEntityValue($data, $valueKey, $type);
161168
}
162169

@@ -184,6 +191,10 @@ public function getEntityValue(array $data, string $key, string $type)
184191
return $data['id'] ?? $data['entity_id'];
185192
}
186193

194+
if ($key === 'uid' && (isset($data['id']) || isset($data['entity_id']))) {
195+
return $this->uid->encode($data['id'] ?? $data['entity_id']);
196+
}
197+
187198
return $data[$key] ?? null;
188199
}
189200
}

0 commit comments

Comments
 (0)