Skip to content

Commit 8bce230

Browse files
committed
PWA-1654: Staged upcoming products don't show up in categoryList query for preview
- modify Category Tree
1 parent 9a68d68 commit 8bce230

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/CategoriesQuery.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8585
throw new GraphQlInputException(__($e->getMessage()));
8686
}
8787

88-
$rootCategoryIds = $filterResult['category_ids'];
89-
$filterResult['items'] = $this->fetchCategories($rootCategoryIds, $info);
88+
$rootCategoryIds = $filterResult['category_ids'] ?? [];
89+
90+
$filterResult['items'] = $this->fetchCategories($rootCategoryIds, $info, $store->getId());
9091
return $filterResult;
9192
}
9293

@@ -95,13 +96,14 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
9596
*
9697
* @param array $categoryIds
9798
* @param ResolveInfo $info
99+
* @param int $storeId
98100
* @return array
99101
*/
100-
private function fetchCategories(array $categoryIds, ResolveInfo $info)
102+
private function fetchCategories(array $categoryIds, ResolveInfo $info, int $storeId)
101103
{
102104
$fetchedCategories = [];
103105
foreach ($categoryIds as $categoryId) {
104-
$categoryTree = $this->categoryTree->getTree($info, $categoryId);
106+
$categoryTree = $this->categoryTree->getTree($info, $categoryId, $storeId);
105107
if (empty($categoryTree)) {
106108
continue;
107109
}

app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryList.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,22 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8181
} catch (InputException $e) {
8282
throw new GraphQlInputException(__($e->getMessage()));
8383
}
84-
85-
return $this->fetchCategories($rootCategoryIds, $info);
84+
return $this->fetchCategories($rootCategoryIds, $info, (int) $store->getId());
8685
}
8786

8887
/**
8988
* Fetch category tree data
9089
*
9190
* @param array $categoryIds
9291
* @param ResolveInfo $info
92+
* @param int $storeId
9393
* @return array
9494
*/
95-
private function fetchCategories(array $categoryIds, ResolveInfo $info)
95+
private function fetchCategories(array $categoryIds, ResolveInfo $info, int $storeId)
9696
{
9797
$fetchedCategories = [];
9898
foreach ($categoryIds as $categoryId) {
99-
$categoryTree = $this->categoryTree->getTree($info, $categoryId);
99+
$categoryTree = $this->categoryTree->getTree($info, $categoryId, $storeId);
100100
if (empty($categoryTree)) {
101101
continue;
102102
}

app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7171
if ($rootCategoryId !== Category::TREE_ROOT_ID) {
7272
$this->checkCategoryIsActive->execute($rootCategoryId);
7373
}
74-
$categoriesTree = $this->categoryTree->getTree($info, $rootCategoryId);
74+
$store = $context->getExtensionAttributes()->getStore();
75+
$categoriesTree = $this->categoryTree->getTree($info, $rootCategoryId, (int)$store->getId());
7576

7677
if (empty($categoriesTree) || ($categoriesTree->count() == 0)) {
7778
throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist'));

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ public function __construct(
8080
*
8181
* @param ResolveInfo $resolveInfo
8282
* @param int $rootCategoryId
83+
* @param int $storeId
8384
* @return \Iterator
85+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
8486
*/
85-
public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId): \Iterator
87+
public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId, int $storeId): \Iterator
8688
{
8789
$categoryQuery = $resolveInfo->fieldNodes[0];
8890
$collection = $this->collectionFactory->create();

0 commit comments

Comments
 (0)