Skip to content

Commit d127628

Browse files
committed
#28563: GraphQL product search does not consider Category Permissions configuration - Pass the context as argument
Pass context to configurable variant collection
1 parent c689798 commit d127628

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/ConfigurableVariant.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
9797
$this->variantCollection->addEavAttributes($fields);
9898
$this->optionCollection->addProductId((int)$value[$linkField]);
9999

100-
$result = function () use ($value, $linkField) {
101-
$children = $this->variantCollection->getChildProductsByParentId((int)$value[$linkField]);
100+
$result = function () use ($value, $linkField, $context) {
101+
$children = $this->variantCollection->getChildProductsByParentId((int)$value[$linkField], $context);
102102
$options = $this->optionCollection->getAttributesByProductId((int)$value[$linkField]);
103103
$variants = [];
104104
/** @var Product $child */

app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\CollectionFactory;
1414
use Magento\Framework\EntityManager\MetadataPool;
1515
use Magento\Framework\Api\SearchCriteriaBuilder;
16+
use Magento\GraphQl\Model\Query\ContextInterface;
1617
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CollectionProcessorInterface;
1718
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CollectionPostProcessor;
1819

@@ -118,11 +119,12 @@ public function addEavAttributes(array $attributeCodes) : void
118119
* Retrieve child products from for passed in parent id.
119120
*
120121
* @param int $id
122+
* @param ContextInterface $context|null
121123
* @return array
122124
*/
123-
public function getChildProductsByParentId(int $id) : array
125+
public function getChildProductsByParentId(int $id, ContextInterface $context = null) : array
124126
{
125-
$childrenMap = $this->fetch();
127+
$childrenMap = $this->fetch($context);
126128

127129
if (!isset($childrenMap[$id])) {
128130
return [];
@@ -134,9 +136,10 @@ public function getChildProductsByParentId(int $id) : array
134136
/**
135137
* Fetch all children products from parent id's.
136138
*
139+
* @param ContextInterface $context|null
137140
* @return array
138141
*/
139-
private function fetch() : array
142+
private function fetch(ContextInterface $context = null) : array
140143
{
141144
if (empty($this->parentProducts) || !empty($this->childrenMap)) {
142145
return $this->childrenMap;
@@ -150,7 +153,8 @@ private function fetch() : array
150153
$this->collectionProcessor->process(
151154
$childCollection,
152155
$this->searchCriteriaBuilder->create(),
153-
$attributeData
156+
$attributeData,
157+
$context
154158
);
155159
$childCollection->load();
156160
$this->collectionPostProcessor->process($childCollection, $attributeData);

0 commit comments

Comments
 (0)