Skip to content

Commit 1cb2f22

Browse files
Maksym Noviknovikor
Maksym Novik
authored andcommitted
Tierprice can't save float percentage value #18651. Display percentage on PDP in case it is set explicitly.
1 parent f2d2f66 commit 1cb2f22

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

app/code/Magento/Catalog/Pricing/Render/PriceBox.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ public function jsonEncode($valueToEncode)
6969
/**
7070
* Get random string
7171
*
72-
* @param int $length
72+
* @param int $length
7373
* @param string|null $chars
74+
*
7475
* @return string
76+
* @throws \Magento\Framework\Exception\LocalizedException
7577
*/
7678
public function getRandomString($length, $chars = null)
7779
{
@@ -93,4 +95,14 @@ public function getCanDisplayQty(Product $product)
9395
}
9496
return true;
9597
}
98+
99+
/**
100+
* @param float $percent
101+
*
102+
* @return string
103+
*/
104+
public function formatPercent(float $percent):string
105+
{
106+
return rtrim(number_format($percent, 2), '.0');
107+
}
96108
}

app/code/Magento/Catalog/view/base/templates/product/price/tier_prices.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ $product = $block->getSaleableItem();
7777
$price['price_qty'],
7878
$priceAmountBlock,
7979
$index,
80-
$tierPriceModel->getSavePercent($price['price'])
80+
$block->formatPercent($price['percentage_value'] ?? $tierPriceModel->getSavePercent($price['price']))
8181
)
8282
: __('Buy %1 for %2 each', $price['price_qty'], $priceAmountBlock);
8383
?>

0 commit comments

Comments
 (0)