Skip to content

Commit bda4a1d

Browse files
committed
MC-42666: GraphQL request returns configurable variants from ALL storeviews
1 parent e6531f1 commit bda4a1d

File tree

3 files changed

+26
-87
lines changed

3 files changed

+26
-87
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute;
1212
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
1313
use Magento\Framework\EntityManager\MetadataPool;
14-
use Magento\Store\Model\Store;
1514

1615
/**
1716
* Build select object for retrieving configurable options.
@@ -44,6 +43,7 @@ public function __construct(Attribute $attributeResource, MetadataPool $metadata
4443
public function getSelect(AbstractAttribute $superAttribute, int $productId)
4544
{
4645
$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
[
@@ -86,7 +86,7 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId)
8686
' AND ',
8787
[
8888
'super_attribute.product_super_attribute_id = attribute_label.product_super_attribute_id',
89-
'attribute_label.store_id = ' . Store::DEFAULT_STORE_ID,
89+
'attribute_label.store_id = 0',
9090
]
9191
),
9292
[]
@@ -111,7 +111,7 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId)
111111
' AND ',
112112
[
113113
'option_value.option_id = entity_value.value',
114-
'option_value.store_id = ' . Store::DEFAULT_STORE_ID,
114+
'option_value.store_id = 0',
115115
]
116116
),
117117
[

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute;
1414
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
1515
use Magento\Framework\EntityManager\MetadataPool;
16-
use Magento\Store\Model\Store;
1716
use Magento\Store\Model\StoreManagerInterface;
1817

1918
/**
@@ -64,8 +63,9 @@ public function __construct(
6463
*/
6564
public function getSelect(AbstractAttribute $superAttribute, int $productId)
6665
{
67-
$store = $this->storeManager->getStore();
6866
$productLinkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
67+
$store = $this->storeManager->getStore();
68+
6969
$select = $this->attributeResource->getConnection()->select()->from(
7070
['super_attribute' => $this->attributeResource->getTable('catalog_product_super_attribute')],
7171
[
@@ -92,23 +92,23 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId)
9292
'entity.entity_id = product_link.product_id',
9393
[]
9494
)->joinInner(
95-
['entity_value' => $superAttribute->getBackendTable()],
95+
['entity_website' => $this->attributeResource->getTable('catalog_product_website')],
9696
implode(
9797
' AND ',
9898
[
99-
'entity_value.attribute_id = super_attribute.attribute_id',
100-
'entity_value.store_id = 0',
101-
"entity_value.$productLinkField = entity.$productLinkField",
99+
"entity_website.product_id = entity.$productLinkField",
100+
"entity_website.website_id = {$store->getWebsiteId()}",
102101
]
103102
),
104103
[]
105104
)->joinInner(
106-
['entity_website' => $this->attributeResource->getTable('catalog_product_website')],
105+
['entity_value' => $superAttribute->getBackendTable()],
107106
implode(
108107
' AND ',
109108
[
110-
"entity_website.product_id = entity.$productLinkField",
111-
"entity_website.website_id = {$store->getWebsiteId()}",
109+
'entity_value.attribute_id = super_attribute.attribute_id',
110+
'entity_value.store_id = 0',
111+
"entity_value.$productLinkField = entity.$productLinkField",
112112
]
113113
),
114114
[]
@@ -118,7 +118,7 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId)
118118
' AND ',
119119
[
120120
'super_attribute.product_super_attribute_id = attribute_label.product_super_attribute_id',
121-
'attribute_label.store_id = ' . Store::DEFAULT_STORE_ID,
121+
'attribute_label.store_id = 0',
122122
]
123123
),
124124
[]
@@ -172,7 +172,7 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId)
172172
' AND ',
173173
[
174174
'default_option_value.option_id = entity_value.value',
175-
'default_option_value.store_id = ' . Store::DEFAULT_STORE_ID,
175+
'default_option_value.store_id = 0',
176176
]
177177
),
178178
[]

app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php

Lines changed: 12 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute;
1313
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
1414
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
15-
use Magento\Framework\App\ScopeInterface;
16-
use Magento\Framework\App\ScopeResolverInterface;
1715
use Magento\Framework\DB\Adapter\AdapterInterface;
1816
use Magento\Framework\DB\Select;
19-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
2017
use PHPUnit\Framework\MockObject\MockObject;
2118
use PHPUnit\Framework\TestCase;
2219

@@ -30,16 +27,6 @@ class AttributeOptionProviderTest extends TestCase
3027
*/
3128
private $model;
3229

33-
/**
34-
* @var ObjectManagerHelper
35-
*/
36-
private $objectManagerHelper;
37-
38-
/**
39-
* @var ScopeResolverInterface|MockObject
40-
*/
41-
private $scopeResolver;
42-
4330
/**
4431
* @var Select|MockObject
4532
*/
@@ -55,11 +42,6 @@ class AttributeOptionProviderTest extends TestCase
5542
*/
5643
private $abstractAttribute;
5744

58-
/**
59-
* @var ScopeInterface|MockObject
60-
*/
61-
private $scope;
62-
6345
/**
6446
* @var Attribute|MockObject
6547
*/
@@ -72,45 +54,13 @@ class AttributeOptionProviderTest extends TestCase
7254

7355
protected function setUp(): void
7456
{
75-
$this->select = $this->getMockBuilder(Select::class)
76-
->setMethods([])
77-
->disableOriginalConstructor()
78-
->getMock();
79-
80-
$this->connectionMock = $this->getMockBuilder(AdapterInterface::class)
81-
->disableOriginalConstructor()
82-
->getMockForAbstractClass();
57+
$this->select = $this->createMock(Select::class);
58+
$this->connectionMock = $this->createMock(AdapterInterface::class);
59+
$this->attributeResource = $this->createMock(Attribute::class);
60+
$this->optionSelectBuilder = $this->createMock(OptionSelectBuilderInterface::class);
61+
$this->abstractAttribute = $this->createMock(AbstractAttribute::class);
8362

84-
$this->scope = $this->getMockBuilder(ScopeInterface::class)
85-
->disableOriginalConstructor()
86-
->getMockForAbstractClass();
87-
88-
$this->scopeResolver = $this->getMockBuilder(ScopeResolverInterface::class)
89-
->disableOriginalConstructor()
90-
->getMockForAbstractClass();
91-
92-
$this->attributeResource = $this->getMockBuilder(Attribute::class)
93-
->disableOriginalConstructor()
94-
->getMock();
95-
96-
$this->optionSelectBuilder = $this->getMockBuilder(OptionSelectBuilderInterface::class)
97-
->disableOriginalConstructor()
98-
->getMockForAbstractClass();
99-
100-
$this->abstractAttribute = $this->getMockBuilder(AbstractAttribute::class)
101-
->setMethods(['getSourceModel', 'getSource'])
102-
->disableOriginalConstructor()
103-
->getMockForAbstractClass();
104-
105-
$this->objectManagerHelper = new ObjectManagerHelper($this);
106-
$this->model = $this->objectManagerHelper->getObject(
107-
AttributeOptionProvider::class,
108-
[
109-
'attributeResource' => $this->attributeResource,
110-
'scopeResolver' => $this->scopeResolver,
111-
'optionSelectBuilder' => $this->optionSelectBuilder,
112-
]
113-
);
63+
$this->model = new AttributeOptionProvider($this->attributeResource, $this->optionSelectBuilder);
11464
}
11565

11666
/**
@@ -119,13 +69,9 @@ protected function setUp(): void
11969
*/
12070
public function testGetAttributeOptions(array $options)
12171
{
122-
$this->scopeResolver->expects($this->any())
123-
->method('getScope')
124-
->willReturn($this->scope);
125-
126-
$this->optionSelectBuilder->expects($this->any())
72+
$this->optionSelectBuilder->expects($this->once())
12773
->method('getSelect')
128-
->with($this->abstractAttribute, 4, $this->scope)
74+
->with($this->abstractAttribute, 4)
12975
->willReturn($this->select);
13076

13177
$this->attributeResource->expects($this->once())
@@ -149,14 +95,7 @@ public function testGetAttributeOptions(array $options)
14995
*/
15096
public function testGetAttributeOptionsWithBackendModel(array $options)
15197
{
152-
$this->scopeResolver->expects($this->any())
153-
->method('getScope')
154-
->willReturn($this->scope);
155-
156-
$source = $this->getMockBuilder(AbstractSource::class)
157-
->disableOriginalConstructor()
158-
->setMethods(['getAllOptions'])
159-
->getMockForAbstractClass();
98+
$source = $this->createMock(AbstractSource::class);
16099
$source->expects($this->once())
161100
->method('getAllOptions')
162101
->willReturn([
@@ -165,16 +104,16 @@ public function testGetAttributeOptionsWithBackendModel(array $options)
165104
['value' => 15, 'label' => 'Option Value for index 15']
166105
]);
167106

168-
$this->abstractAttribute->expects($this->any())
107+
$this->abstractAttribute->expects($this->atLeastOnce())
169108
->method('getSource')
170109
->willReturn($source);
171110
$this->abstractAttribute->expects($this->atLeastOnce())
172111
->method('getSourceModel')
173112
->willReturn('getSourceModel value');
174113

175-
$this->optionSelectBuilder->expects($this->any())
114+
$this->optionSelectBuilder->expects($this->once())
176115
->method('getSelect')
177-
->with($this->abstractAttribute, 1, $this->scope)
116+
->with($this->abstractAttribute, 1)
178117
->willReturn($this->select);
179118

180119
$this->attributeResource->expects($this->once())

0 commit comments

Comments
 (0)