Skip to content

Commit 56cf69c

Browse files
committed
MC-42666: GraphQL request returns configurable variants from ALL storeviews
1 parent 06b9e44 commit 56cf69c

File tree

11 files changed

+544
-221
lines changed

11 files changed

+544
-221
lines changed

app/code/Magento/ConfigurableProduct/Model/AttributeOptionProvider.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@
88

99
use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface;
1010
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
11+
use Magento\Framework\App\ScopeResolverInterface;
1112
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute;
13+
use Magento\Framework\DB\Select;
1214

1315
/**
1416
* Provider for retrieving configurable options.
1517
*/
1618
class AttributeOptionProvider implements AttributeOptionProviderInterface
1719
{
20+
/**
21+
* @var ScopeResolverInterface
22+
*/
23+
private $scopeResolver;
24+
1825
/**
1926
* @var Attribute
2027
*/
@@ -27,13 +34,16 @@ class AttributeOptionProvider implements AttributeOptionProviderInterface
2734

2835
/**
2936
* @param Attribute $attributeResource
37+
* @param ScopeResolverInterface $scopeResolver,
3038
* @param OptionSelectBuilderInterface $optionSelectBuilder
3139
*/
3240
public function __construct(
3341
Attribute $attributeResource,
42+
ScopeResolverInterface $scopeResolver,
3443
OptionSelectBuilderInterface $optionSelectBuilder
3544
) {
3645
$this->attributeResource = $attributeResource;
46+
$this->scopeResolver = $scopeResolver;
3747
$this->optionSelectBuilder = $optionSelectBuilder;
3848
}
3949

@@ -42,7 +52,8 @@ public function __construct(
4252
*/
4353
public function getAttributeOptions(AbstractAttribute $superAttribute, $productId)
4454
{
45-
$select = $this->optionSelectBuilder->getSelect($superAttribute, (int) $productId);
55+
$scope = $this->scopeResolver->getScope();
56+
$select = $this->optionSelectBuilder->getSelect($superAttribute, $productId, $scope);
4657
$data = $this->attributeResource->getConnection()->fetchAll($select);
4758

4859
if ($superAttribute->getSourceModel()) {

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

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,47 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
declare(strict_types=1);
7-
86
namespace Magento\ConfigurableProduct\Model\ResourceModel\Attribute;
97

10-
use Magento\Catalog\Api\Data\ProductInterface;
118
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute;
129
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
13-
use Magento\Framework\EntityManager\MetadataPool;
10+
use Magento\Framework\App\ScopeInterface;
11+
use Magento\Framework\DB\Select;
1412

1513
/**
1614
* Build select object for retrieving configurable options.
1715
*/
1816
class OptionSelectBuilder implements OptionSelectBuilderInterface
1917
{
2018
/**
19+
* Configurable Attribute Resource Model.
20+
*
2121
* @var Attribute
2222
*/
2323
private $attributeResource;
2424

2525
/**
26-
* @var MetadataPool
26+
* Option Provider.
27+
*
28+
* @var OptionProvider
2729
*/
28-
private $metadataPool;
30+
private $attributeOptionProvider;
2931

3032
/**
3133
* @param Attribute $attributeResource
32-
* @param MetadataPool $metadataPool
34+
* @param OptionProvider $attributeOptionProvider
3335
*/
34-
public function __construct(Attribute $attributeResource, MetadataPool $metadataPool)
36+
public function __construct(Attribute $attributeResource, OptionProvider $attributeOptionProvider)
3537
{
3638
$this->attributeResource = $attributeResource;
37-
$this->metadataPool = $metadataPool;
39+
$this->attributeOptionProvider = $attributeOptionProvider;
3840
}
3941

4042
/**
4143
* @inheritdoc
4244
*/
43-
public function getSelect(AbstractAttribute $superAttribute, int $productId)
45+
public function getSelect(AbstractAttribute $superAttribute, int $productId, ScopeInterface $scope)
4446
{
45-
$productLinkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
46-
4747
$select = $this->attributeResource->getConnection()->select()->from(
4848
['super_attribute' => $this->attributeResource->getTable('catalog_product_super_attribute')],
4949
[
@@ -55,7 +55,7 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId)
5555
]
5656
)->joinInner(
5757
['product_entity' => $this->attributeResource->getTable('catalog_product_entity')],
58-
"product_entity.$productLinkField = super_attribute.product_id",
58+
"product_entity.{$this->attributeOptionProvider->getProductEntityLinkField()} = super_attribute.product_id",
5959
[]
6060
)->joinInner(
6161
['product_link' => $this->attributeResource->getTable('catalog_product_super_link')],
@@ -76,7 +76,8 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId)
7676
[
7777
'entity_value.attribute_id = super_attribute.attribute_id',
7878
'entity_value.store_id = 0',
79-
"entity_value.$productLinkField = entity.$productLinkField",
79+
"entity_value.{$this->attributeOptionProvider->getProductEntityLinkField()} = "
80+
. "entity.{$this->attributeOptionProvider->getProductEntityLinkField()}",
8081
]
8182
),
8283
[]
@@ -86,7 +87,7 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId)
8687
' AND ',
8788
[
8889
'super_attribute.product_super_attribute_id = attribute_label.product_super_attribute_id',
89-
'attribute_label.store_id = 0',
90+
'attribute_label.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID,
9091
]
9192
),
9293
[]
@@ -105,19 +106,34 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId)
105106
);
106107

107108
if (!$superAttribute->getSourceModel()) {
108-
$select->joinLeft(
109+
$select->columns(
110+
[
111+
'option_title' => $this->attributeResource->getConnection()->getIfNullSql(
112+
'option_value.value',
113+
'default_option_value.value'
114+
),
115+
'default_title' => 'default_option_value.value',
116+
]
117+
)->joinLeft(
109118
['option_value' => $this->attributeResource->getTable('eav_attribute_option_value')],
110119
implode(
111120
' AND ',
112121
[
113122
'option_value.option_id = entity_value.value',
114-
'option_value.store_id = 0',
123+
'option_value.store_id = ' . $scope->getId(),
115124
]
116125
),
117-
[
118-
'option_title' => 'option_value.value',
119-
'default_title' => 'option_value.value',
120-
]
126+
[]
127+
)->joinLeft(
128+
['default_option_value' => $this->attributeResource->getTable('eav_attribute_option_value')],
129+
implode(
130+
' AND ',
131+
[
132+
'default_option_value.option_id = entity_value.value',
133+
'default_option_value.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID,
134+
]
135+
),
136+
[]
121137
);
122138
}
123139

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\ConfigurableProduct\Model\ResourceModel\Attribute;
77

88
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
9+
use Magento\Framework\App\ScopeInterface;
910
use Magento\Framework\DB\Select;
1011

1112
/**
@@ -18,7 +19,8 @@ interface OptionSelectBuilderInterface
1819
*
1920
* @param AbstractAttribute $superAttribute
2021
* @param int $productId
22+
* @param ScopeInterface $scope
2123
* @return Select
2224
*/
23-
public function getSelect(AbstractAttribute $superAttribute, int $productId);
25+
public function getSelect(AbstractAttribute $superAttribute, int $productId, ScopeInterface $scope);
2426
}

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

Lines changed: 0 additions & 184 deletions
This file was deleted.

0 commit comments

Comments
 (0)