Skip to content

Commit 9782f39

Browse files
ENGCOM-1204: [Backport 2.1] Configurable product price options by store #14479
- Merge Pull Request #14479 from simpleadm/magento2:backport/2.1-configurable-lowest-price-provider-by-store - Merged commits: 1. fb03cfb
2 parents 2e9f1db + fb03cfb commit 9782f39

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
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;
13+
use Magento\Framework\App\ObjectManager;
1214

1315
/**
1416
* Retrieve list of products where each product contains lower price than others at least for one possible price type
@@ -31,7 +33,12 @@ class LowestPriceOptionsProvider implements LowestPriceOptionsProviderInterface
3133
private $collectionFactory;
3234

3335
/**
34-
* Key is product id. Value is prepared product collection
36+
* @var StoreManagerInterface
37+
*/
38+
private $storeManager;
39+
40+
/**
41+
* Key is product id and store id. Value is array of prepared linked products
3542
*
3643
* @var array
3744
*/
@@ -41,34 +48,39 @@ class LowestPriceOptionsProvider implements LowestPriceOptionsProviderInterface
4148
* @param ResourceConnection $resourceConnection
4249
* @param LinkedProductSelectBuilderInterface $linkedProductSelectBuilder
4350
* @param CollectionFactory $collectionFactory
51+
* @param StoreManagerInterface $storeManager
4452
*/
4553
public function __construct(
4654
ResourceConnection $resourceConnection,
4755
LinkedProductSelectBuilderInterface $linkedProductSelectBuilder,
48-
CollectionFactory $collectionFactory
56+
CollectionFactory $collectionFactory,
57+
StoreManagerInterface $storeManager = null
4958
) {
5059
$this->resource = $resourceConnection;
5160
$this->linkedProductSelectBuilder = $linkedProductSelectBuilder;
5261
$this->collectionFactory = $collectionFactory;
62+
$this->storeManager = $storeManager
63+
?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
5364
}
5465

5566
/**
5667
* {@inheritdoc}
5768
*/
5869
public function getProducts(ProductInterface $product)
5970
{
60-
if (!isset($this->productsMap[$product->getId()])) {
71+
$key = $this->storeManager->getStore()->getId() . '-' . $product->getId();
72+
if (!isset($this->productsMap[$key])) {
6173
$productIds = $this->resource->getConnection()->fetchCol(
6274
'(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($product->getId())) . ')'
6375
);
6476

65-
$this->productsMap[$product->getId()] = $this->collectionFactory->create()
77+
$this->productsMap[$key] = $this->collectionFactory->create()
6678
->addAttributeToSelect(
6779
['price', 'special_price', 'special_from_date', 'special_to_date', 'tax_class_id']
6880
)
6981
->addIdFilter($productIds)
7082
->getItems();
7183
}
72-
return $this->productsMap[$product->getId()];
84+
return $this->productsMap[$key];
7385
}
7486
}

0 commit comments

Comments
 (0)