Skip to content

Commit 0b60a10

Browse files
authored
Merge pull request #3241 from romainruaud/fix_graphql-category-uid-in
Fix #3231 allow fetching products with category_uid IN clauses.
2 parents fb66665 + f04fff9 commit 0b60a10

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

src/module-elasticsuite-virtual-category/Plugin/Search/RequestMapperPlugin.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,14 @@ public function afterGetFilters(
9999
) {
100100
$storeId = $containerConfiguration->getStoreId();
101101
if ($this->isEnabled($containerConfiguration)) {
102+
$result = $this->decodeCategoryUid($result);
102103
if (isset($result['category.category_id']) && !isset($result['category.category_uid'])) {
103104
$result[] = $this->getCategoriesQuery($result['category.category_id'], $storeId);
104105

105106
unset($result['category.category_id']);
106-
} elseif (isset($result['category.category_uid']) && isset($result['category.category_uid']['eq']) &&
107-
!isset($result['category.category_id'])) {
108-
$categoryUid[] = $this->uidEncoder->decode($result['category.category_uid']['eq']);
107+
} elseif (isset($result['category.category_uid']) && !isset($result['category.category_id'])) {
108+
$result[] = $this->getCategoriesQuery($result['category.category_uid'], $storeId);
109109

110-
$result[] = $this->getCategoriesQuery($categoryUid, $storeId);
111110
unset($result['category.category_uid']);
112111
} elseif (isset($result['category.category_id']) && isset($result['category.category_uid'])) {
113112
$result[] = $this->getCategoriesQuery($result['category.category_id'], $storeId);
@@ -181,4 +180,33 @@ private function getCategorySubQuery($categoryId, $storeId)
181180

182181
return $this->filterProvider->getQueryFilter($category);
183182
}
183+
184+
/**
185+
* Decode category_uid params if present in the request, because they are base64 encoded.
186+
*
187+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
188+
*
189+
* @param array $result The array containing potentially the params.
190+
*
191+
* @return array
192+
* @throws \Magento\Framework\GraphQl\Exception\GraphQlInputException
193+
*/
194+
private function decodeCategoryUid(&$result)
195+
{
196+
if (isset($result['category.category_uid'])) {
197+
$decodeCb = function (string $categoryUid) {
198+
return $this->uidEncoder->decode($categoryUid);
199+
};
200+
201+
foreach ($result['category.category_uid'] as $operator => &$categoryIds) {
202+
if (!is_array($categoryIds)) {
203+
$categoryIds = [$categoryIds];
204+
}
205+
206+
$categoryIds = array_map($decodeCb, $categoryIds);
207+
}
208+
}
209+
210+
return $result;
211+
}
184212
}

0 commit comments

Comments
 (0)