Skip to content

Commit 3a7e6c1

Browse files
author
Oleksandr Dubovyk
committed
MC-30255: In Stock Alert Email Shows Incorrect Item Pricing
1 parent 8483aed commit 3a7e6c1

File tree

12 files changed

+29
-23
lines changed

12 files changed

+29
-23
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ public function __construct(
8585
/**
8686
* {@inheritdoc}
8787
*/
88-
public function build($productId)
88+
public function build(int $productId, int $storeId) : array
8989
{
9090
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
9191
$productTable = $this->resource->getTableName('catalog_product_entity');
92-
$websiteId = $this->storeManager->getStore()->getWebsiteId();
92+
$websiteId = $this->storeManager->getStore($storeId)->getWebsiteId();
9393
$customerGroupId = $this->customerSession->getCustomerGroupId();
9494

9595
$priceSelect = $this->resource->getConnection()->select()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function __construct(
7474
/**
7575
* @inheritdoc
7676
*/
77-
public function build($productId)
77+
public function build(int $productId, int $storeId) : array
7878
{
7979
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
8080
$priceAttribute = $this->eavConfig->getAttribute(Product::ENTITY, 'price');
@@ -104,7 +104,7 @@ public function build($productId)
104104

105105
if (!$this->catalogHelper->isPriceGlobal()) {
106106
$priceSelectStore = clone $priceSelect;
107-
$priceSelectStore->where('t.store_id = ?', $this->storeManager->getStore()->getId());
107+
$priceSelectStore->where('t.store_id = ?', $storeId);
108108
$selects[] = $priceSelectStore;
109109
}
110110

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ public function __construct(
9090
/**
9191
* {@inheritdoc}
9292
*/
93-
public function build($productId)
93+
public function build(int $productId, int $storeId) : array
9494
{
9595
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
9696
$connection = $this->resource->getConnection();
9797
$specialPriceAttribute = $this->eavConfig->getAttribute(Product::ENTITY, 'special_price');
9898
$specialPriceFromDate = $this->eavConfig->getAttribute(Product::ENTITY, 'special_from_date');
9999
$specialPriceToDate = $this->eavConfig->getAttribute(Product::ENTITY, 'special_to_date');
100-
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
100+
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore($storeId));
101101
$currentDate = $this->dateTime->formatDate($timestamp, false);
102102
$productTable = $this->resource->getTableName('catalog_product_entity');
103103

@@ -145,7 +145,7 @@ public function build($productId)
145145

146146
if (!$this->catalogHelper->isPriceGlobal()) {
147147
$priceSelectStore = clone $specialPrice;
148-
$priceSelectStore->where('t.store_id = ?', $this->storeManager->getStore()->getId());
148+
$priceSelectStore->where('t.store_id = ?', $storeId);
149149
$selects[] = $priceSelectStore;
150150
}
151151

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function __construct(
7474
/**
7575
* {@inheritdoc}
7676
*/
77-
public function build($productId)
77+
public function build(int $productId, int $storeId) : array
7878
{
7979
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
8080
$productTable = $this->resource->getTableName('catalog_product_entity');
@@ -103,7 +103,7 @@ public function build($productId)
103103

104104
if (!$this->catalogHelper->isPriceGlobal()) {
105105
$priceSelectStore = clone $priceSelect;
106-
$priceSelectStore->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId());
106+
$priceSelectStore->where('t.website_id = ?', $this->storeManager->getStore($storeId)->getWebsiteId());
107107
$selects[] = $priceSelectStore;
108108
}
109109

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public function __construct($linkedProductSelectBuilder)
2424
/**
2525
* {@inheritdoc}
2626
*/
27-
public function build($productId)
27+
public function build(int $productId, int $storeId) : array
2828
{
2929
$selects = [];
3030
foreach ($this->linkedProductSelectBuilder as $productSelectBuilder) {
31-
$selects = array_merge($selects, $productSelectBuilder->build($productId));
31+
$selects = array_merge($selects, $productSelectBuilder->build($productId, $storeId));
3232
}
3333

3434
return $selects;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ interface LinkedProductSelectBuilderInterface
1212
{
1313
/**
1414
* @param int $productId
15+
* @param int $storeId
1516
* @return \Magento\Framework\DB\Select[]
1617
*/
17-
public function build($productId);
18+
public function build(int $productId, int $storeId) : array;
1819
}

app/code/Magento/CatalogRule/Model/ResourceModel/Product/LinkedProductSelectBuilderByCatalogRulePrice.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ public function __construct(
8686
/**
8787
* @inheritdoc
8888
*/
89-
public function build($productId)
89+
public function build(int $productId, int $storeId) : array
9090
{
91-
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
91+
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore($storeId));
9292
$currentDate = $this->dateTime->formatDate($timestamp, false);
9393
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
9494
$productTable = $this->resource->getTableName('catalog_product_entity');
@@ -108,7 +108,7 @@ public function build($productId)
108108
sprintf('t.product_id = %s.%s', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS, $linkField),
109109
[]
110110
)->where('parent.entity_id = ?', $productId)
111-
->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId())
111+
->where('t.website_id = ?', $this->storeManager->getStore($storeId)->getWebsiteId())
112112
->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId())
113113
->where('t.rule_date = ?', $currentDate)
114114
->order('t.rule_price ' . Select::SQL_ASC)

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/LinkedProductSelectBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public function __construct(
4141
/**
4242
* {@inheritdoc}
4343
*/
44-
public function build($productId)
44+
public function build(int $productId, int $storeId) : array
4545
{
46-
$selects = $this->linkedProductSelectBuilder->build($productId);
46+
$selects = $this->linkedProductSelectBuilder->build($productId, $storeId);
4747

4848
foreach ($selects as $select) {
4949
$this->baseSelectProcessor->process($select);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ public function __construct(
6666
*/
6767
public function getProducts(ProductInterface $product)
6868
{
69-
$key = $this->storeManager->getStore()->getId() . '-' . $product->getId();
69+
$productId = $product->getId();
70+
$storeId = $product->getStoreId();
71+
$key = $storeId . '-' . $productId;
7072
if (!isset($this->linkedProductMap[$key])) {
7173
$productIds = $this->resource->getConnection()->fetchCol(
72-
'(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($product->getId())) . ')'
74+
'(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($productId, $storeId)) . ')'
7375
);
7476

7577
$this->linkedProductMap[$key] = $this->collectionFactory->create()

app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Product/LinkedProductSelectBuilderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected function setUp()
5050
public function testBuild()
5151
{
5252
$productId = 42;
53+
$storeId = 1;
5354

5455
/** @var Select|\PHPUnit_Framework_MockObject_MockObject $selectMock */
5556
$selectMock = $this->getMockBuilder(Select::class)
@@ -67,6 +68,6 @@ public function testBuild()
6768
->method('process')
6869
->with($selectMock);
6970

70-
$this->assertEquals($expectedResult, $this->subject->build($productId));
71+
$this->assertEquals($expectedResult, $this->subject->build($productId, $storeId));
7172
}
7273
}

0 commit comments

Comments
 (0)