Skip to content

Commit 8e6c315

Browse files
author
vnayda
committed
MAGETWO-59953: [Backport] Configurable product option price is displayed incorrectly per website for 2.1.3
- fix unit tests
1 parent 01c935d commit 8e6c315

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/StatusBaseSelectProcessor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ public function process(Select $select)
6161
$select->joinLeft(
6262
['status_global_attr' => $statusAttribute->getBackendTable()],
6363
"status_global_attr.{$linkField} = " . self::PRODUCT_TABLE_ALIAS . ".{$linkField}"
64-
. ' AND status_global_attr.attribute_id = ' . (int) $statusAttribute->getAttributeId()
65-
. ' AND status_global_attr.store_id = ' . Store::DEFAULT_STORE_ID,
64+
. ' AND status_global_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId()
65+
. ' AND status_global_attr.store_id = ' . Store::DEFAULT_STORE_ID,
6666
[]
6767
);
6868

6969
$select->joinLeft(
7070
['status_attr' => $statusAttribute->getBackendTable()],
7171
"status_attr.{$linkField} = " . self::PRODUCT_TABLE_ALIAS . ".{$linkField}"
72-
. ' AND status_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId()
73-
. ' AND status_attr.store_id = ' . $this->storeResolver->getCurrentStoreId(),
72+
. ' AND status_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId()
73+
. ' AND status_attr.store_id = ' . $this->storeResolver->getCurrentStoreId(),
7474
[]
7575
);
7676

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/StatusBaseSelectProcessorTest.php

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Magento\Framework\EntityManager\EntityMetadataInterface;
1717
use Magento\Framework\EntityManager\MetadataPool;
1818
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
19+
use Magento\Store\Api\StoreResolverInterface;
20+
use Magento\Store\Model\Store;
1921

2022
class StatusBaseSelectProcessorTest extends \PHPUnit_Framework_TestCase
2123
{
@@ -29,6 +31,11 @@ class StatusBaseSelectProcessorTest extends \PHPUnit_Framework_TestCase
2931
*/
3032
private $metadataPool;
3133

34+
/**
35+
* @var StoreResolverInterface|\PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
private $storeResolver;
38+
3239
/**
3340
* @var Select|\PHPUnit_Framework_MockObject_MockObject
3441
*/
@@ -43,19 +50,22 @@ protected function setUp()
4350
{
4451
$this->eavConfig = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
4552
$this->metadataPool = $this->getMockBuilder(MetadataPool::class)->disableOriginalConstructor()->getMock();
53+
$this->storeResolver = $this->getMockBuilder(StoreResolverInterface::class)->getMock();
4654
$this->select = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock();
4755

4856
$this->statusBaseSelectProcessor = (new ObjectManager($this))->getObject(StatusBaseSelectProcessor::class, [
4957
'eavConfig' => $this->eavConfig,
5058
'metadataPool' => $this->metadataPool,
59+
'storeResolver' => $this->storeResolver,
5160
]);
5261
}
5362

5463
public function testProcess()
5564
{
5665
$linkField = 'link_field';
5766
$backendTable = 'backend_table';
58-
$attributeId = 'attribute_id';
67+
$attributeId = 2;
68+
$currentStoreId = 1;
5969

6070
$metadata = $this->getMock(EntityMetadataInterface::class);
6171
$metadata->expects($this->once())
@@ -66,35 +76,49 @@ public function testProcess()
6676
->with(ProductInterface::class)
6777
->willReturn($metadata);
6878

79+
/** @var AttributeInterface|\PHPUnit_Framework_MockObject_MockObject $statusAttribute */
6980
$statusAttribute = $this->getMockBuilder(AttributeInterface::class)
7081
->setMethods(['getBackendTable', 'getAttributeId'])
7182
->getMock();
72-
$statusAttribute->expects($this->once())
83+
$statusAttribute->expects($this->atLeastOnce())
7384
->method('getBackendTable')
7485
->willReturn($backendTable);
75-
$statusAttribute->expects($this->once())
86+
$statusAttribute->expects($this->atLeastOnce())
7687
->method('getAttributeId')
7788
->willReturn($attributeId);
7889
$this->eavConfig->expects($this->once())
7990
->method('getAttribute')
8091
->with(Product::ENTITY, ProductInterface::STATUS)
8192
->willReturn($statusAttribute);
8293

83-
$this->select->expects($this->once())
84-
->method('join')
94+
$this->storeResolver->expects($this->once())
95+
->method('getCurrentStoreId')
96+
->willReturn($currentStoreId);
97+
98+
$this->select->expects($this->at(0))
99+
->method('joinLeft')
85100
->with(
86-
['status_attr' => $backendTable],
87-
sprintf('status_attr.%s = %s.%1$s', $linkField, BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
101+
['status_global_attr' => $backendTable],
102+
"status_global_attr.{$linkField} = "
103+
. BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS . ".{$linkField}"
104+
. " AND status_global_attr.attribute_id = {$attributeId}"
105+
. ' AND status_global_attr.store_id = ' . Store::DEFAULT_STORE_ID,
88106
[]
89107
)
90108
->willReturnSelf();
91109
$this->select->expects($this->at(1))
92-
->method('where')
93-
->with('status_attr.attribute_id = ?', $attributeId)
110+
->method('joinLeft')
111+
->with(
112+
['status_attr' => $backendTable],
113+
"status_attr.{$linkField} = " . BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS . ".{$linkField}"
114+
. " AND status_attr.attribute_id = {$attributeId}"
115+
. " AND status_attr.store_id = {$currentStoreId}",
116+
[]
117+
)
94118
->willReturnSelf();
95119
$this->select->expects($this->at(2))
96120
->method('where')
97-
->with('status_attr.value = ?', Status::STATUS_ENABLED)
121+
->with('IFNULL(status_attr.value, status_global_attr.value) = ?', Status::STATUS_ENABLED)
98122
->willReturnSelf();
99123

100124
$this->assertEquals($this->select, $this->statusBaseSelectProcessor->process($this->select));

0 commit comments

Comments
 (0)