Skip to content

Commit fea8b14

Browse files
ENGCOM-8158: Old price excluding TAX shown correct on Product Page #27832
2 parents 7eb3def + 0f82c4a commit fea8b14

File tree

8 files changed

+57
-12
lines changed

8 files changed

+57
-12
lines changed

app/code/Magento/Catalog/Block/Product/View.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ public function getJsonConfig()
196196
'productId' => (int)$product->getId(),
197197
'priceFormat' => $this->_localeFormat->getPriceFormat(),
198198
'prices' => [
199+
'baseOldPrice' => [
200+
'amount' => $priceInfo->getPrice('regular_price')->getAmount()->getBaseAmount() * 1,
201+
'adjustments' => []
202+
],
199203
'oldPrice' => [
200204
'amount' => $priceInfo->getPrice('regular_price')->getAmount()->getValue() * 1,
201205
'adjustments' => []

app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ protected function getOptionPrices()
303303

304304
$prices[$product->getId()] =
305305
[
306+
'baseOldPrice' => [
307+
'amount' => $this->localeFormat->getNumber(
308+
$priceInfo->getPrice('regular_price')->getAmount()->getBaseAmount()
309+
),
310+
],
306311
'oldPrice' => [
307312
'amount' => $this->localeFormat->getNumber(
308313
$priceInfo->getPrice('regular_price')->getAmount()->getValue()

app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable/Variations/Prices.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public function getFormattedPrices(\Magento\Framework\Pricing\PriceInfo\Base $pr
3939
$finalPrice = $priceInfo->getPrice('final_price');
4040

4141
return [
42+
'baseOldPrice' => [
43+
'amount' => $this->localeFormat->getNumber($regularPrice->getAmount()->getBaseAmount()),
44+
],
4245
'oldPrice' => [
4346
'amount' => $this->localeFormat->getNumber($regularPrice->getAmount()->getValue()),
4447
],

app/code/Magento/ConfigurableProduct/Test/Unit/Block/Product/View/Type/ConfigurableTest.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,11 @@ public function cacheKeyProvider(): array
254254
* @param string|null $priceCurrency
255255
* @param int|null $customerGroupId
256256
*/
257-
public function testGetCacheKeyInfo(array $expected, ?string $priceCurrency = null, ?int $customerGroupId = null)
258-
{
257+
public function testGetCacheKeyInfo(
258+
array $expected,
259+
?string $priceCurrency = null,
260+
?int $customerGroupId = null
261+
): void {
259262
$storeMock = $this->getMockBuilder(StoreInterface::class)
260263
->setMethods(['getCurrentCurrency'])
261264
->getMockForAbstractClass();
@@ -282,7 +285,7 @@ public function testGetCacheKeyInfo(array $expected, ?string $priceCurrency = nu
282285
/**
283286
* Check that getJsonConfig() method returns expected value
284287
*/
285-
public function testGetJsonConfig()
288+
public function testGetJsonConfig(): void
286289
{
287290
$productId = 1;
288291
$amount = 10.50;
@@ -347,6 +350,9 @@ public function testGetJsonConfig()
347350
->with($priceInfoMock)
348351
->willReturn(
349352
[
353+
'baseOldPrice' => [
354+
'amount' => $amount,
355+
],
350356
'oldPrice' => [
351357
'amount' => $amount,
352358
],
@@ -386,6 +392,9 @@ private function getExpectedArray($productId, $amount, $priceQty, $percentage):
386392
'currencyFormat' => '%s',
387393
'optionPrices' => [
388394
$productId => [
395+
'baseOldPrice' => [
396+
'amount' => $amount,
397+
],
389398
'oldPrice' => [
390399
'amount' => $amount,
391400
],
@@ -403,12 +412,15 @@ private function getExpectedArray($productId, $amount, $priceQty, $percentage):
403412
],
404413
],
405414
'msrpPrice' => [
406-
'amount' => null ,
415+
'amount' => null,
407416
]
408417
],
409418
],
410419
'priceFormat' => [],
411420
'prices' => [
421+
'baseOldPrice' => [
422+
'amount' => $amount,
423+
],
412424
'oldPrice' => [
413425
'amount' => $amount,
414426
],
@@ -434,7 +446,7 @@ private function getExpectedArray($productId, $amount, $priceQty, $percentage):
434446
* @param MockObject $productMock
435447
* @return MockObject
436448
*/
437-
private function getProductTypeMock(MockObject $productMock)
449+
private function getProductTypeMock(MockObject $productMock): MockObject
438450
{
439451
$currencyMock = $this->getMockBuilder(Currency::class)
440452
->disableOriginalConstructor()

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/Configurable/Variations/PricesTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ protected function setUp(): void
3636
);
3737
}
3838

39-
public function testGetFormattedPrices()
39+
public function testGetFormattedPrices(): void
4040
{
4141
$expected = [
42+
'baseOldPrice' => [
43+
'amount' => 1000
44+
],
4245
'oldPrice' => [
4346
'amount' => 500
4447
],
@@ -60,8 +63,8 @@ public function testGetFormattedPrices()
6063

6164
$this->localeFormatMock->expects($this->atLeastOnce())
6265
->method('getNumber')
63-
->withConsecutive([500], [1000], [500])
64-
->will($this->onConsecutiveCalls(500, 1000, 500));
66+
->withConsecutive([1000], [500], [1000], [500])
67+
->will($this->onConsecutiveCalls(1000, 500, 1000, 500));
6568

6669
$this->assertEquals($expected, $this->model->getFormattedPrices($priceInfoMock));
6770
}

app/code/Magento/Tax/Pricing/Render/Adjustment.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public function __construct(
3838
}
3939

4040
/**
41+
* Apply the right HTML output to the adjustment
42+
*
4143
* @return string
4244
*/
4345
protected function apply()
@@ -173,4 +175,16 @@ public function displayPriceExcludingTax()
173175
{
174176
return $this->taxHelper->displayPriceExcludingTax();
175177
}
178+
179+
/**
180+
* Obtain a value for data-price-type attribute
181+
*
182+
* @return string
183+
*/
184+
public function getDataPriceType(): string
185+
{
186+
return $this->amountRender->getPriceType() === 'finalPrice'
187+
? 'basePrice'
188+
: 'base' . ucfirst($this->amountRender->getPriceType());
189+
}
176190
}

app/code/Magento/Tax/view/base/templates/pricing/adjustment.phtml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
?>
77

88
<?php /** @var \Magento\Tax\Pricing\Render\Adjustment $block */ ?>
9+
<?php /** @var $escaper \Magento\Framework\Escaper */ ?>
910

10-
<?php if ($block->displayBothPrices()) : ?>
11-
<span id="<?= $block->escapeHtmlAttr($block->buildIdWithPrefix('price-excluding-tax-')) ?>"
12-
data-label="<?= $block->escapeHtmlAttr(__('Excl. Tax')) ?>"
11+
<?php if ($block->displayBothPrices()): ?>
12+
<span id="<?= $escaper->escapeHtmlAttr($block->buildIdWithPrefix('price-excluding-tax-')) ?>"
13+
data-label="<?= $escaper->escapeHtmlAttr(__('Excl. Tax')) ?>"
1314
data-price-amount="<?= /* @noEscape */ $block->getRawAmount() ?>"
14-
data-price-type="basePrice"
15+
data-price-type="<?= $escaper->escapeHtmlAttr($block->getDataPriceType()); ?>"
1516
class="price-wrapper price-excluding-tax">
1617
<span class="price"><?= /* @noEscape */ $block->getDisplayAmountExclTax() ?></span></span>
1718
<?php endif; ?>

dev/tests/integration/testsuite/Magento/Swatches/Block/Product/Renderer/Configurable/PriceTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,23 @@ public function childProductsDataProvider(): array
116116
],
117117
'expected_data' => [
118118
[
119+
'baseOldPrice' => ['amount' => 150],
119120
'oldPrice' => ['amount' => 150],
120121
'basePrice' => ['amount' => 50],
121122
'finalPrice' => ['amount' => 50],
122123
'tierPrices' => [],
123124
'msrpPrice' => ['amount' => null],
124125
],
125126
[
127+
'baseOldPrice' => ['amount' => 150],
126128
'oldPrice' => ['amount' => 150],
127129
'basePrice' => ['amount' => 58.55],
128130
'finalPrice' => ['amount' => 58.55],
129131
'tierPrices' => [],
130132
'msrpPrice' => ['amount' => null],
131133
],
132134
[
135+
'baseOldPrice' => ['amount' => 150],
133136
'oldPrice' => ['amount' => 150],
134137
'basePrice' => ['amount' => 75],
135138
'finalPrice' => ['amount' => 75],

0 commit comments

Comments
 (0)