Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old price excluding TAX shown correct on Product Page #27832

Merged
merged 9 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/code/Magento/Catalog/Block/Product/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ public function getJsonConfig()
'productId' => (int)$product->getId(),
'priceFormat' => $this->_localeFormat->getPriceFormat(),
'prices' => [
'baseOldPrice' => [
'amount' => $priceInfo->getPrice('regular_price')->getAmount()->getBaseAmount() * 1,
'adjustments' => []
],
'oldPrice' => [
'amount' => $priceInfo->getPrice('regular_price')->getAmount()->getValue() * 1,
'adjustments' => []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ protected function getOptionPrices()

$prices[$product->getId()] =
[
'baseOldPrice' => [
'amount' => $this->localeFormat->getNumber(
$priceInfo->getPrice('regular_price')->getAmount()->getBaseAmount()
),
],
'oldPrice' => [
'amount' => $this->localeFormat->getNumber(
$priceInfo->getPrice('regular_price')->getAmount()->getValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public function getFormattedPrices(\Magento\Framework\Pricing\PriceInfo\Base $pr
$finalPrice = $priceInfo->getPrice('final_price');

return [
'baseOldPrice' => [
'amount' => $this->localeFormat->getNumber($regularPrice->getAmount()->getBaseAmount()),
],
'oldPrice' => [
'amount' => $this->localeFormat->getNumber($regularPrice->getAmount()->getValue()),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,11 @@ public function cacheKeyProvider(): array
* @param string|null $priceCurrency
* @param int|null $customerGroupId
*/
public function testGetCacheKeyInfo(array $expected, ?string $priceCurrency = null, ?int $customerGroupId = null)
{
public function testGetCacheKeyInfo(
array $expected,
?string $priceCurrency = null,
?int $customerGroupId = null
): void {
$storeMock = $this->getMockBuilder(StoreInterface::class)
->setMethods(['getCurrentCurrency'])
->getMockForAbstractClass();
Expand All @@ -282,7 +285,7 @@ public function testGetCacheKeyInfo(array $expected, ?string $priceCurrency = nu
/**
* Check that getJsonConfig() method returns expected value
*/
public function testGetJsonConfig()
public function testGetJsonConfig(): void
{
$productId = 1;
$amount = 10.50;
Expand Down Expand Up @@ -347,6 +350,9 @@ public function testGetJsonConfig()
->with($priceInfoMock)
->willReturn(
[
'baseOldPrice' => [
'amount' => $amount,
],
'oldPrice' => [
'amount' => $amount,
],
Expand Down Expand Up @@ -386,6 +392,9 @@ private function getExpectedArray($productId, $amount, $priceQty, $percentage):
'currencyFormat' => '%s',
'optionPrices' => [
$productId => [
'baseOldPrice' => [
'amount' => $amount,
],
'oldPrice' => [
'amount' => $amount,
],
Expand All @@ -403,12 +412,15 @@ private function getExpectedArray($productId, $amount, $priceQty, $percentage):
],
],
'msrpPrice' => [
'amount' => null ,
'amount' => null,
]
],
],
'priceFormat' => [],
'prices' => [
'baseOldPrice' => [
'amount' => $amount,
],
'oldPrice' => [
'amount' => $amount,
],
Expand All @@ -434,7 +446,7 @@ private function getExpectedArray($productId, $amount, $priceQty, $percentage):
* @param MockObject $productMock
* @return MockObject
*/
private function getProductTypeMock(MockObject $productMock)
private function getProductTypeMock(MockObject $productMock): MockObject
{
$currencyMock = $this->getMockBuilder(Currency::class)
->disableOriginalConstructor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ protected function setUp(): void
);
}

public function testGetFormattedPrices()
public function testGetFormattedPrices(): void
{
$expected = [
'baseOldPrice' => [
'amount' => 1000
],
'oldPrice' => [
'amount' => 500
],
Expand All @@ -60,8 +63,8 @@ public function testGetFormattedPrices()

$this->localeFormatMock->expects($this->atLeastOnce())
->method('getNumber')
->withConsecutive([500], [1000], [500])
->will($this->onConsecutiveCalls(500, 1000, 500));
->withConsecutive([1000], [500], [1000], [500])
->will($this->onConsecutiveCalls(1000, 500, 1000, 500));

$this->assertEquals($expected, $this->model->getFormattedPrices($priceInfoMock));
}
Expand Down
14 changes: 14 additions & 0 deletions app/code/Magento/Tax/Pricing/Render/Adjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function __construct(
}

/**
* Apply the right HTML output to the adjustment
*
* @return string
*/
protected function apply()
Expand Down Expand Up @@ -173,4 +175,16 @@ public function displayPriceExcludingTax()
{
return $this->taxHelper->displayPriceExcludingTax();
}

/**
* Obtain a value for data-price-type attribute
*
* @return string
*/
public function getDataPriceType(): string
{
return $this->amountRender->getPriceType() === 'finalPrice'
? 'basePrice'
: 'base' . ucfirst($this->amountRender->getPriceType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
?>

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

<?php if ($block->displayBothPrices()) : ?>
<span id="<?= $block->escapeHtmlAttr($block->buildIdWithPrefix('price-excluding-tax-')) ?>"
data-label="<?= $block->escapeHtmlAttr(__('Excl. Tax')) ?>"
<?php if ($block->displayBothPrices()): ?>
<span id="<?= $escaper->escapeHtmlAttr($block->buildIdWithPrefix('price-excluding-tax-')) ?>"
data-label="<?= $escaper->escapeHtmlAttr(__('Excl. Tax')) ?>"
data-price-amount="<?= /* @noEscape */ $block->getRawAmount() ?>"
data-price-type="basePrice"
data-price-type="<?= $escaper->escapeHtmlAttr($block->getDataPriceType()); ?>"
class="price-wrapper price-excluding-tax">
<span class="price"><?= /* @noEscape */ $block->getDisplayAmountExclTax() ?></span></span>
<?php endif; ?>
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,23 @@ public function childProductsDataProvider(): array
],
'expected_data' => [
[
'baseOldPrice' => ['amount' => 150],
'oldPrice' => ['amount' => 150],
'basePrice' => ['amount' => 50],
'finalPrice' => ['amount' => 50],
'tierPrices' => [],
'msrpPrice' => ['amount' => null],
],
[
'baseOldPrice' => ['amount' => 150],
'oldPrice' => ['amount' => 150],
'basePrice' => ['amount' => 58.55],
'finalPrice' => ['amount' => 58.55],
'tierPrices' => [],
'msrpPrice' => ['amount' => null],
],
[
'baseOldPrice' => ['amount' => 150],
'oldPrice' => ['amount' => 150],
'basePrice' => ['amount' => 75],
'finalPrice' => ['amount' => 75],
Expand Down