diff --git a/app/code/Magento/ConfigurableProduct/Pricing/Price/LowestPriceOptionsProvider.php b/app/code/Magento/ConfigurableProduct/Pricing/Price/LowestPriceOptionsProvider.php index 66bc3db7ee89d..d3ce508b31e0d 100644 --- a/app/code/Magento/ConfigurableProduct/Pricing/Price/LowestPriceOptionsProvider.php +++ b/app/code/Magento/ConfigurableProduct/Pricing/Price/LowestPriceOptionsProvider.php @@ -9,6 +9,7 @@ use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface; use Magento\Framework\App\ResourceConnection; use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; +use Magento\Store\Model\StoreManagerInterface; /** * 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 private $collectionFactory; /** - * Key is product id. Value is array of prepared linked products + * @var StoreManagerInterface + */ + private $storeManager; + + /** + * Key is product id and store id. Value is array of prepared linked products * * @var array */ @@ -41,15 +47,18 @@ class LowestPriceOptionsProvider implements LowestPriceOptionsProviderInterface * @param ResourceConnection $resourceConnection * @param LinkedProductSelectBuilderInterface $linkedProductSelectBuilder * @param CollectionFactory $collectionFactory + * @param StoreManagerInterface $storeManager */ public function __construct( ResourceConnection $resourceConnection, LinkedProductSelectBuilderInterface $linkedProductSelectBuilder, - CollectionFactory $collectionFactory + CollectionFactory $collectionFactory, + StoreManagerInterface $storeManager ) { $this->resource = $resourceConnection; $this->linkedProductSelectBuilder = $linkedProductSelectBuilder; $this->collectionFactory = $collectionFactory; + $this->storeManager = $storeManager; } /** @@ -57,18 +66,19 @@ public function __construct( */ public function getProducts(ProductInterface $product) { - if (!isset($this->linkedProductMap[$product->getId()])) { + $key = $this->storeManager->getStore()->getId() . '-' . $product->getId(); + if (!isset($this->linkedProductMap[$key])) { $productIds = $this->resource->getConnection()->fetchCol( '(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($product->getId())) . ')' ); - $this->linkedProductMap[$product->getId()] = $this->collectionFactory->create() + $this->linkedProductMap[$key] = $this->collectionFactory->create() ->addAttributeToSelect( ['price', 'special_price', 'special_from_date', 'special_to_date', 'tax_class_id'] ) ->addIdFilter($productIds) ->getItems(); } - return $this->linkedProductMap[$product->getId()]; + return $this->linkedProductMap[$key]; } } diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Pricing/Price/LowestPriceOptionsProviderTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Pricing/Price/LowestPriceOptionsProviderTest.php index ceeb242a750a2..7c83645a9fda3 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Pricing/Price/LowestPriceOptionsProviderTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Pricing/Price/LowestPriceOptionsProviderTest.php @@ -9,6 +9,9 @@ use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface; +use Magento\Store\Model\StoreManagerInterface; +use Magento\Store\Api\Data\StoreInterface; +use Magento\Store\Model\Store; class LowestPriceOptionsProviderTest extends \PHPUnit\Framework\TestCase { @@ -42,6 +45,16 @@ class LowestPriceOptionsProviderTest extends \PHPUnit\Framework\TestCase */ private $productCollection; + /** + * @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $storeManagerMock; + + /** + * @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $storeMock; + protected function setUp() { $this->connection = $this @@ -68,6 +81,11 @@ protected function setUp() ->setMethods(['create']) ->getMock(); $this->collectionFactory->expects($this->once())->method('create')->willReturn($this->productCollection); + $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class) + ->getMockForAbstractClass(); + $this->storeMock = $this->getMockBuilder(StoreInterface::class) + ->setMethods(['getId']) + ->getMockForAbstractClass(); $objectManager = new ObjectManager($this); $this->model = $objectManager->getObject( @@ -76,6 +94,7 @@ protected function setUp() 'resourceConnection' => $this->resourceConnection, 'linkedProductSelectBuilder' => $this->linkedProductSelectBuilder, 'collectionFactory' => $this->collectionFactory, + 'storeManager' => $this->storeManagerMock, ] ); } @@ -94,6 +113,13 @@ public function testGetProducts() ->willReturnSelf(); $this->productCollection->expects($this->once())->method('addIdFilter')->willReturnSelf(); $this->productCollection->expects($this->once())->method('getItems')->willReturn($linkedProducts); + $this->storeManagerMock->expects($this->any()) + ->method('getStore') + ->with(Store::DEFAULT_STORE_ID) + ->willReturn($this->storeMock); + $this->storeMock->expects($this->any()) + ->method('getId') + ->willReturn(Store::DEFAULT_STORE_ID); $this->assertEquals($linkedProducts, $this->model->getProducts($product)); }