Skip to content

Commit 42070df

Browse files
committed
B2B-2404: Optimize Product Permissions in GraphQL resolver
- fix website visibility issue
1 parent 9d9f073 commit 42070df

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/Product/CollectionProcessor/VisibilityStatusProcessor.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,15 @@ public function process(
3535
array $attributeNames,
3636
ContextInterface $context = null
3737
): Collection {
38-
$websiteId = $context->getExtensionAttributes()->getStore()->getWebsiteId();
3938
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
4039
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
41-
$collection->addWebsiteFilter([$websiteId]);
40+
if ($context) {
41+
$store = $context->getExtensionAttributes()->getStore();
42+
if ($store) {
43+
$websiteId = $store->getWebsiteId();
44+
$collection->addWebsiteFilter([$websiteId]);
45+
}
46+
}
4247

4348
return $collection;
4449
}

app/code/Magento/RelatedProductGraphQl/Model/Resolver/Batch/AbstractLikedProducts.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,15 @@ abstract protected function getLinkType(): int;
8080
* @param \Magento\Catalog\Api\Data\ProductInterface[] $products
8181
* @param string[] $loadAttributes
8282
* @param int $linkType
83+
* @param ContextInterface $context
8384
* @return \Magento\Catalog\Api\Data\ProductInterface[][]
8485
*/
85-
private function findRelations(array $products, array $loadAttributes, int $linkType): array
86-
{
86+
private function findRelations(
87+
array $products,
88+
array $loadAttributes,
89+
int $linkType,
90+
ContextInterface $context
91+
): array {
8792
//Loading relations
8893
$relations = $this->relatedProductDataProvider->getRelations($products, $linkType);
8994
if (!$relations) {
@@ -96,7 +101,8 @@ private function findRelations(array $products, array $loadAttributes, int $link
96101
$this->searchCriteriaBuilder->create(),
97102
$loadAttributes,
98103
false,
99-
true
104+
true,
105+
$context
100106
);
101107
//Filling related products map.
102108
/** @var \Magento\Catalog\Api\Data\ProductInterface[] $relatedProducts */
@@ -144,7 +150,7 @@ public function resolve(ContextInterface $context, Field $field, array $requests
144150
$fields = array_unique(array_merge([], ...$fields));
145151

146152
//Finding relations.
147-
$related = $this->findRelations($products, $fields, $this->getLinkType());
153+
$related = $this->findRelations($products, $fields, $this->getLinkType(), $context);
148154

149155
//Matching requests with responses.
150156
$response = new BatchResponse();

0 commit comments

Comments
 (0)