Skip to content

Commit 2697216

Browse files
committed
MC-42666: GraphQL request returns configurable variants from ALL storeviews
1 parent 912857f commit 2697216

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute;
99
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
1010
use Magento\Framework\App\ScopeInterface;
11-
use Magento\Framework\DB\Select;
1211

1312
/**
1413
* Build select object for retrieving configurable options.
@@ -44,6 +43,7 @@ public function __construct(Attribute $attributeResource, OptionProvider $attrib
4443
*/
4544
public function getSelect(AbstractAttribute $superAttribute, int $productId, ScopeInterface $scope)
4645
{
46+
$productLinkField = $this->attributeOptionProvider->getProductEntityLinkField();
4747
$select = $this->attributeResource->getConnection()->select()->from(
4848
['super_attribute' => $this->attributeResource->getTable('catalog_product_super_attribute')],
4949
[
@@ -76,8 +76,17 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId, Sco
7676
[
7777
'entity_value.attribute_id = super_attribute.attribute_id',
7878
'entity_value.store_id = 0',
79-
"entity_value.{$this->attributeOptionProvider->getProductEntityLinkField()} = "
80-
. "entity.{$this->attributeOptionProvider->getProductEntityLinkField()}",
79+
"entity_value.$productLinkField = entity.$productLinkField",
80+
]
81+
),
82+
[]
83+
)->joinInner(
84+
['entity_website' => $this->attributeResource->getTable('catalog_product_website')],
85+
implode(
86+
' AND ',
87+
[
88+
"entity_website.product_id = entity.$productLinkField",
89+
"entity_website.website_id = {$scope->getWebsiteId()}",
8190
]
8291
),
8392
[]

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ public function addEavAttributes(array $attributeCodes) : void
120120
* Retrieve child products from for passed in parent id.
121121
*
122122
* @param int $id
123-
* @param ContextInterface|null $context
123+
* @param ContextInterface $context
124124
* @return array
125125
*/
126-
public function getChildProductsByParentId(int $id, ContextInterface $context = null) : array
126+
public function getChildProductsByParentId(int $id, ContextInterface $context) : array
127127
{
128128
$childrenMap = $this->fetch($context);
129129

@@ -137,10 +137,10 @@ public function getChildProductsByParentId(int $id, ContextInterface $context =
137137
/**
138138
* Fetch all children products from parent id's.
139139
*
140-
* @param ContextInterface|null $context
140+
* @param ContextInterface $context
141141
* @return array
142142
*/
143-
private function fetch(ContextInterface $context = null) : array
143+
private function fetch(ContextInterface $context) : array
144144
{
145145
if (empty($this->parentProducts) || !empty($this->childrenMap)) {
146146
return $this->childrenMap;
@@ -151,6 +151,7 @@ private function fetch(ContextInterface $context = null) : array
151151
/** @var ChildCollection $childCollection */
152152
$childCollection = $this->childCollectionFactory->create();
153153
$childCollection->setProductFilter($product);
154+
$childCollection->addWebsiteFilter($context->getExtensionAttributes()->getStore()->getWebsiteId());
154155
$this->collectionProcessor->process(
155156
$childCollection,
156157
$this->searchCriteriaBuilder->create(),

0 commit comments

Comments
 (0)