Skip to content

Commit 0251589

Browse files
AC-1214 Price mismatch for global scope with multiple websites
1 parent 302f6c5 commit 0251589

File tree

3 files changed

+133
-4
lines changed

3 files changed

+133
-4
lines changed

app/code/Magento/Eav/Model/ResourceModel/ReadHandler.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Exception;
1010
use Magento\Eav\Model\Config;
1111
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
12+
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
1213
use Magento\Framework\DataObject;
1314
use Magento\Framework\DB\Select;
1415
use Magento\Framework\DB\Sql\UnionExpression;
@@ -135,12 +136,15 @@ public function execute($entityType, $entityData, $arguments = [])
135136
$attributeTables = [];
136137
$attributesMap = [];
137138
$selects = [];
139+
$attributeScopeGlobal = [];
138140

139141
/** @var AbstractAttribute $attribute */
140142
foreach ($this->getEntityAttributes($entityType, new DataObject($entityData)) as $attribute) {
141143
if (!$attribute->isStatic()) {
142144
$attributeTables[$attribute->getBackend()->getTable()][] = $attribute->getAttributeId();
143145
$attributesMap[$attribute->getAttributeId()] = $attribute->getAttributeCode();
146+
$attributeScopeGlobal[$attribute->getAttributeId()] =
147+
$attribute->getIsGlobal() === ScopedAttributeInterface::SCOPE_GLOBAL;
144148
}
145149
}
146150
if (count($attributeTables)) {
@@ -174,6 +178,12 @@ public function execute($entityType, $entityData, $arguments = [])
174178
$attributes = $connection->fetchAll($orderedUnionSelect);
175179
foreach ($attributes as $attributeValue) {
176180
if (isset($attributesMap[$attributeValue['attribute_id']])) {
181+
if (isset($attributeScopeGlobal[$attributeValue['attribute_id']]) && $attributeScopeGlobal[$attributeValue['attribute_id']]) {
182+
if ((int)$attributeValue['store_id'] !== \Magento\Store\Model\Store::DEFAULT_STORE_ID) {
183+
continue;
184+
}
185+
$entityData[$attributesMap[$attributeValue['attribute_id']]] = $attributeValue['value'];
186+
}
177187
$entityData[$attributesMap[$attributeValue['attribute_id']]] = $attributeValue['value'];
178188
} else {
179189
$this->logger->warning(

app/code/Magento/Eav/Test/Unit/Model/ResourceModel/ReadHandlerTest.php

Lines changed: 122 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,17 @@ protected function setUp(): void
6060
->willReturn($this->metadataMock);
6161
$this->configMock = $args['config'];
6262
$this->scopeResolverMock = $args['scopeResolver'];
63+
64+
$scopeMock = $this->getMockBuilder(\Magento\Framework\Model\Entity\ScopeInterface::class)
65+
->disableOriginalConstructor()
66+
->getMock();
67+
$fallback = clone $scopeMock;
68+
$scopeMock->method('getIdentifier')->willReturn('store_id');
69+
$scopeMock->method('getValue')->willReturn(1);
70+
$scopeMock->method('getFallback')->willReturn($fallback);
71+
6372
$this->scopeResolverMock->method('getEntityContext')
64-
->willReturn([]);
73+
->willReturn([$scopeMock]);
6574

6675
$this->readHandler = $objectManager->getObject(ReadHandler::class, $args);
6776
}
@@ -73,8 +82,12 @@ protected function setUp(): void
7382
* @param bool $isStatic
7483
* @dataProvider executeDataProvider
7584
*/
76-
public function testExecute($eavEntityType, $callNum, array $expected, $isStatic = true)
77-
{
85+
public function testExecute(
86+
$eavEntityType,
87+
$callNum,
88+
array $expected,
89+
$isStatic = true
90+
) {
7891
$entityData = ['linkField' => 'theLinkField'];
7992
$this->metadataMock->method('getEavEntityType')
8093
->willReturn($eavEntityType);
@@ -105,10 +118,83 @@ public function testExecute($eavEntityType, $callNum, array $expected, $isStatic
105118
->willReturn('linkField');
106119

107120
$attributeMock = $this->getMockBuilder(AbstractAttribute::class)
121+
->setMethods(['getAttributeCode', 'isScopeWebsite', 'isStatic', 'getBackend', 'getAttributeId'])
122+
->disableOriginalConstructor()
123+
->getMockForAbstractClass();
124+
$attributeMock->method('isStatic')
125+
->willReturn($isStatic);
126+
$backendMock = $this->getMockBuilder(AbstractBackend::class)
127+
->disableOriginalConstructor()
128+
->getMock();
129+
$backendMock->method('getTable')
130+
->willReturn('backendTable');
131+
$attributeMock->method('getBackend')
132+
->willReturn($backendMock);
133+
$attributeMock->method('getAttributeId')
134+
->willReturn('attributeId');
135+
$attributeMock->method('getAttributeCode')
136+
->willReturn('attributeCode');
137+
$this->configMock->expects($this->exactly($callNum))
138+
->method('getEntityAttributes')
139+
->willReturn([$attributeMock]);
140+
$this->assertEquals($expected, $this->readHandler->execute('entity_type', $entityData));
141+
}
142+
143+
/**
144+
* @param string $eavEntityType
145+
* @param int $callNum
146+
* @param array $expected
147+
* @param bool $isStatic
148+
* @param null|int $isGlobalScope
149+
* @throws \Magento\Framework\Exception\ConfigurationMismatchException
150+
* @throws \Magento\Framework\Exception\LocalizedException
151+
* @dataProvider executeGlobalScopeDataProvider
152+
*/
153+
public function testExecuteGlobalScope(
154+
$eavEntityType,
155+
$callNum,
156+
array $expected,
157+
$isStatic = true,
158+
$isGlobalScope = null
159+
) {
160+
$entityData = ['linkField' => 'theLinkField'];
161+
$this->metadataMock->method('getEavEntityType')
162+
->willReturn($eavEntityType);
163+
$connectionMock = $this->getMockBuilder(AdapterInterface::class)
164+
->disableOriginalConstructor()
165+
->getMockForAbstractClass();
166+
$selectMock = $this->getMockBuilder(Select::class)
108167
->disableOriginalConstructor()
109168
->getMock();
169+
$selectMock->method('from')
170+
->willReturnSelf();
171+
$selectMock->method('where')
172+
->willReturnSelf();
173+
$connectionMock->method('select')
174+
->willReturn($selectMock);
175+
$connectionMock->method('fetchAll')
176+
->willReturn(
177+
[
178+
[
179+
'attribute_id' => 'attributeId',
180+
'value' => 'attributeValue',
181+
'store_id' => 0
182+
]
183+
]
184+
);
185+
$this->metadataMock->method('getEntityConnection')
186+
->willReturn($connectionMock);
187+
$this->metadataMock->method('getLinkField')
188+
->willReturn('linkField');
189+
190+
$attributeMock = $this->getMockBuilder(AbstractAttribute::class)
191+
->setMethods(['getAttributeCode', 'isScopeWebsite', 'getIsGlobal', 'isStatic', 'getBackend', 'getAttributeId'])
192+
->disableOriginalConstructor()
193+
->getMockForAbstractClass();
110194
$attributeMock->method('isStatic')
111195
->willReturn($isStatic);
196+
$attributeMock->method('getIsGlobal')
197+
->willReturn($isGlobalScope);
112198
$backendMock = $this->getMockBuilder(AbstractBackend::class)
113199
->disableOriginalConstructor()
114200
->getMock();
@@ -142,6 +228,39 @@ public function executeDataProvider()
142228
'attributeCode' => 'attributeValue'
143229
],
144230
false
231+
]
232+
];
233+
}
234+
235+
/**
236+
* @return array
237+
*/
238+
public function executeGlobalScopeDataProvider()
239+
{
240+
return [
241+
'null entity type' => [null, 0, ['linkField' => 'theLinkField']],
242+
'static attribute' => ['env-entity-type', 1, ['linkField' => 'theLinkField']],
243+
'non-static attribute' => [
244+
'env-entity-type',
245+
1,
246+
[
247+
'linkField' => 'theLinkField',
248+
'attributeCode' => 'attributeValue'
249+
],
250+
false,
251+
null,
252+
1
253+
],
254+
'non-static attribute2' => [
255+
'env-entity-type',
256+
1,
257+
[
258+
'linkField' => 'theLinkField',
259+
'attributeCode' => 'attributeValue'
260+
],
261+
false,
262+
1,
263+
0
145264
],
146265
];
147266
}

app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ protected function _assignProducts(): self
250250
$this->_productIds
251251
)->addAttributeToSelect(
252252
$this->_quoteConfig->getProductAttributes()
253-
);
253+
)->addPriceData();
254254
$this->skipStockStatusFilter($productCollection);
255255
$productCollection->addOptionsToResult()->addStoreFilter()->addUrlRewrite();
256256

0 commit comments

Comments
 (0)