Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 4e429c4

Browse files
author
Stanislav Idolov
authored
ENGCOM-1217: Configurable product price options by store #13933
2 parents b7ca049 + d2657f1 commit 4e429c4

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

app/code/Magento/ConfigurableProduct/Pricing/Price/LowestPriceOptionsProvider.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface;
1010
use Magento\Framework\App\ResourceConnection;
1111
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
12+
use Magento\Store\Model\StoreManagerInterface;
1213

1314
/**
1415
* Retrieve list of products where each product contains lower price than others at least for one possible price type
@@ -31,7 +32,12 @@ class LowestPriceOptionsProvider implements LowestPriceOptionsProviderInterface
3132
private $collectionFactory;
3233

3334
/**
34-
* Key is product id. Value is array of prepared linked products
35+
* @var StoreManagerInterface
36+
*/
37+
private $storeManager;
38+
39+
/**
40+
* Key is product id and store id. Value is array of prepared linked products
3541
*
3642
* @var array
3743
*/
@@ -41,34 +47,38 @@ class LowestPriceOptionsProvider implements LowestPriceOptionsProviderInterface
4147
* @param ResourceConnection $resourceConnection
4248
* @param LinkedProductSelectBuilderInterface $linkedProductSelectBuilder
4349
* @param CollectionFactory $collectionFactory
50+
* @param StoreManagerInterface $storeManager
4451
*/
4552
public function __construct(
4653
ResourceConnection $resourceConnection,
4754
LinkedProductSelectBuilderInterface $linkedProductSelectBuilder,
48-
CollectionFactory $collectionFactory
55+
CollectionFactory $collectionFactory,
56+
StoreManagerInterface $storeManager
4957
) {
5058
$this->resource = $resourceConnection;
5159
$this->linkedProductSelectBuilder = $linkedProductSelectBuilder;
5260
$this->collectionFactory = $collectionFactory;
61+
$this->storeManager = $storeManager;
5362
}
5463

5564
/**
5665
* {@inheritdoc}
5766
*/
5867
public function getProducts(ProductInterface $product)
5968
{
60-
if (!isset($this->linkedProductMap[$product->getId()])) {
69+
$key = $this->storeManager->getStore()->getId() . '-' . $product->getId();
70+
if (!isset($this->linkedProductMap[$key])) {
6171
$productIds = $this->resource->getConnection()->fetchCol(
6272
'(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($product->getId())) . ')'
6373
);
6474

65-
$this->linkedProductMap[$product->getId()] = $this->collectionFactory->create()
75+
$this->linkedProductMap[$key] = $this->collectionFactory->create()
6676
->addAttributeToSelect(
6777
['price', 'special_price', 'special_from_date', 'special_to_date', 'tax_class_id']
6878
)
6979
->addIdFilter($productIds)
7080
->getItems();
7181
}
72-
return $this->linkedProductMap[$product->getId()];
82+
return $this->linkedProductMap[$key];
7383
}
7484
}

app/code/Magento/ConfigurableProduct/Test/Unit/Pricing/Price/LowestPriceOptionsProviderTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface;
12+
use Magento\Store\Model\StoreManagerInterface;
13+
use Magento\Store\Api\Data\StoreInterface;
14+
use Magento\Store\Model\Store;
1215

1316
class LowestPriceOptionsProviderTest extends \PHPUnit\Framework\TestCase
1417
{
@@ -42,6 +45,16 @@ class LowestPriceOptionsProviderTest extends \PHPUnit\Framework\TestCase
4245
*/
4346
private $productCollection;
4447

48+
/**
49+
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
50+
*/
51+
private $storeManagerMock;
52+
53+
/**
54+
* @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject
55+
*/
56+
private $storeMock;
57+
4558
protected function setUp()
4659
{
4760
$this->connection = $this
@@ -68,6 +81,11 @@ protected function setUp()
6881
->setMethods(['create'])
6982
->getMock();
7083
$this->collectionFactory->expects($this->once())->method('create')->willReturn($this->productCollection);
84+
$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
85+
->getMockForAbstractClass();
86+
$this->storeMock = $this->getMockBuilder(StoreInterface::class)
87+
->setMethods(['getId'])
88+
->getMockForAbstractClass();
7189

7290
$objectManager = new ObjectManager($this);
7391
$this->model = $objectManager->getObject(
@@ -76,6 +94,7 @@ protected function setUp()
7694
'resourceConnection' => $this->resourceConnection,
7795
'linkedProductSelectBuilder' => $this->linkedProductSelectBuilder,
7896
'collectionFactory' => $this->collectionFactory,
97+
'storeManager' => $this->storeManagerMock,
7998
]
8099
);
81100
}
@@ -94,6 +113,13 @@ public function testGetProducts()
94113
->willReturnSelf();
95114
$this->productCollection->expects($this->once())->method('addIdFilter')->willReturnSelf();
96115
$this->productCollection->expects($this->once())->method('getItems')->willReturn($linkedProducts);
116+
$this->storeManagerMock->expects($this->any())
117+
->method('getStore')
118+
->with(Store::DEFAULT_STORE_ID)
119+
->willReturn($this->storeMock);
120+
$this->storeMock->expects($this->any())
121+
->method('getId')
122+
->willReturn(Store::DEFAULT_STORE_ID);
97123

98124
$this->assertEquals($linkedProducts, $this->model->getProducts($product));
99125
}

0 commit comments

Comments
 (0)