Skip to content

Commit d4f3adf

Browse files
author
Prabhu Ram
authored
Merge pull request #6805 from magento-honey-badgers/PWA-1654
[honey] PWA-1654: Staged upcoming products don't show up in categoryList query
2 parents dcbbe78 + ab4f367 commit d4f3adf

File tree

10 files changed

+58
-25
lines changed

10 files changed

+58
-25
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, (int) $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();

app/code/Magento/CatalogUrlRewriteGraphQl/Model/DataProvider/UrlRewrite/CatalogTreeDataProvider.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,18 @@ public function __construct(
5252
* @param string $entity_type
5353
* @param int $id
5454
* @param ResolveInfo|null $info
55+
* @param int|null $storeId
5556
* @return array
5657
* @throws GraphQlNoSuchEntityException
5758
*/
5859
public function getData(
5960
string $entity_type,
6061
int $id,
61-
ResolveInfo $info = null
62+
ResolveInfo $info = null,
63+
int $storeId = null
6264
): array {
6365
$categoryId = (int)$id;
64-
$categoriesTree = $this->categoryTree->getTree($info, $categoryId);
66+
$categoriesTree = $this->categoryTree->getTree($info, $categoryId, $storeId);
6567
if (empty($categoriesTree) || ($categoriesTree->count() == 0)) {
6668
throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist'));
6769
}

app/code/Magento/CatalogUrlRewriteGraphQl/Model/DataProvider/UrlRewrite/ProductDataProvider.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\CatalogUrlRewriteGraphQl\Model\DataProvider\UrlRewrite;
99

1010
use Magento\Catalog\Model\ProductRepository;
11+
use Magento\Framework\Exception\NoSuchEntityException;
1112
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1213
use Magento\UrlRewriteGraphQl\Model\DataProvider\EntityDataProviderInterface;
1314

@@ -28,17 +29,23 @@ public function __construct(
2829
}
2930

3031
/**
31-
* Get product data
32+
* Get catalog tree data
3233
*
3334
* @param string $entity_type
3435
* @param int $id
3536
* @param ResolveInfo|null $info
37+
* @param int|null $storeId
3638
* @return array
37-
* @throws \Magento\Framework\Exception\NoSuchEntityException
39+
* @throws NoSuchEntityException
40+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3841
*/
39-
public function getData(string $entity_type, int $id, ResolveInfo $info = null): array
40-
{
41-
$product = $this->productRepository->getById($id);
42+
public function getData(
43+
string $entity_type,
44+
int $id,
45+
ResolveInfo $info = null,
46+
int $storeId = null
47+
): array {
48+
$product = $this->productRepository->getById($id, false, $storeId);
4249
$result = $product->getData();
4350
$result['model'] = $product;
4451
return $result;

app/code/Magento/CmsUrlRewriteGraphQl/Model/DataProvider/UrlRewrite/Page.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@ public function __construct(
3535
* @param string $entity_type
3636
* @param int $id
3737
* @param ResolveInfo|null $info
38+
* @param int|null $storeId
3839
* @return array
3940
* @throws NoSuchEntityException
41+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4042
*/
41-
public function getData(string $entity_type, int $id, ResolveInfo $info = null): array
42-
{
43+
public function getData(
44+
string $entity_type,
45+
int $id,
46+
ResolveInfo $info = null,
47+
int $storeId = null
48+
): array {
4349
$result = $this->pageDataProvider->getDataByPageId((int)$id);
4450
$result['type_id'] = $entity_type;
4551
return $result;

app/code/Magento/UrlRewriteGraphQl/Model/DataProvider/EntityDataProviderComposite.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,20 @@ public function __construct(array $dataProviders = [])
3333
* @param string $entity_type
3434
* @param int $id
3535
* @param ResolveInfo|null $info
36+
* @param int|null $storeId
3637
* @return array
3738
*/
38-
public function getData(string $entity_type, int $id, ResolveInfo $info = null): array
39-
{
39+
public function getData(
40+
string $entity_type,
41+
int $id,
42+
ResolveInfo $info = null,
43+
int $storeId = null
44+
): array {
4045
return $this->dataProviders[strtolower($entity_type)]->getData(
4146
$entity_type,
4247
$id,
43-
$info
48+
$info,
49+
$storeId
4450
);
4551
}
4652
}

app/code/Magento/UrlRewriteGraphQl/Model/DataProvider/EntityDataProviderInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ interface EntityDataProviderInterface
1717
* @param string $entity_type
1818
* @param int $id
1919
* @param ResolveInfo|null $info
20+
* @param int|null $storeId
2021
* @return array
2122
*/
2223
public function getData(
2324
string $entity_type,
2425
int $id,
25-
ResolveInfo $info = null
26+
ResolveInfo $info = null,
27+
int $storeId = null
2628
): array;
2729
}

app/code/Magento/UrlRewriteGraphQl/Model/Resolver/Route.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,14 @@ public function resolve(
5656
$value,
5757
$args
5858
);
59-
59+
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
6060
if ($resultArray) {
61-
$result = $this->entityDataProviderComposite->getData($resultArray['type'], (int)$resultArray['id'], $info);
61+
$result = $this->entityDataProviderComposite->getData(
62+
$resultArray['type'],
63+
(int)$resultArray['id'],
64+
$info,
65+
$storeId
66+
);
6267
$result['redirect_code'] = $resultArray['redirect_code'];
6368
$result['relative_url'] = $resultArray['relative_url'];
6469
$result['type'] = $resultArray['type'];

0 commit comments

Comments
 (0)