Skip to content

Commit 8681d30

Browse files
committed
B2B-2404: Optimize Product Permissions in GraphQL resolver
1 parent 7af071a commit 8681d30

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

app/code/Magento/BundleGraphQl/Model/Resolver/Options/Label.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public function resolve(
5656
$this->product->addProductSku($value['sku']);
5757
$this->product->addEavAttributes(['name']);
5858

59-
$result = function () use ($value) {
60-
$productData = $this->product->getProductBySku($value['sku']);
59+
$result = function () use ($value, $context) {
60+
$productData = $this->product->getProductBySku($value['sku'], $context);
6161
/** @var \Magento\Catalog\Model\Product $productModel */
6262
$productModel = isset($productData['model']) ? $productData['model'] : null;
6363
return $productModel ? $productModel->getName() : null;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6363
$fields = $this->productFieldsSelector->getProductFieldsFromInfo($info);
6464
$this->productDataProvider->addEavAttributes($fields);
6565

66-
$result = function () use ($value) {
67-
$data = $value['product'] ?? $this->productDataProvider->getProductBySku($value['sku']);
66+
$result = function () use ($value, $context) {
67+
$data = $value['product'] ?? $this->productDataProvider->getProductBySku($value['sku'], $context);
6868
if (empty($data)) {
6969
return null;
7070
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,12 @@ public function addEavAttributes(array $attributeCodes) : void
103103
* Get product from result set.
104104
*
105105
* @param string $sku
106+
* @param null|ContextInterface $context
106107
* @return array
107108
*/
108-
public function getProductBySku(string $sku) : array
109+
public function getProductBySku(string $sku, ContextInterface $context = null) : array
109110
{
110-
$products = $this->fetch();
111+
$products = $this->fetch($context);
111112

112113
if (!isset($products[$sku])) {
113114
return [];
@@ -119,9 +120,10 @@ public function getProductBySku(string $sku) : array
119120
/**
120121
* Fetch product data and return in array format. Keys for products will be their skus.
121122
*
123+
* @param null|ContextInterface $context
122124
* @return array
123125
*/
124-
private function fetch() : array
126+
private function fetch(ContextInterface $context = null) : array
125127
{
126128
if (empty($this->productSkus) || !empty($this->productList)) {
127129
return $this->productList;
@@ -132,7 +134,8 @@ private function fetch() : array
132134
$this->searchCriteriaBuilder->create(),
133135
$this->attributeCodes,
134136
false,
135-
false
137+
true,
138+
$context
136139
);
137140

138141
/** @var \Magento\Catalog\Model\Product $product */

0 commit comments

Comments
 (0)