Skip to content

Commit eba29bf

Browse files
ENGCOM-5132: [Backport] Tierprice can t save float percentage value 18651 #22936
2 parents eef6a04 + ea78332 commit eba29bf

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Pricing\Render;
79

810
use Magento\Catalog\Model\Product;
@@ -71,7 +73,9 @@ public function jsonEncode($valueToEncode)
7173
*
7274
* @param int $length
7375
* @param string|null $chars
76+
*
7477
* @return string
78+
* @throws \Magento\Framework\Exception\LocalizedException
7579
*/
7680
public function getRandomString($length, $chars = null)
7781
{
@@ -93,4 +97,21 @@ public function getCanDisplayQty(Product $product)
9397
}
9498
return true;
9599
}
100+
101+
/**
102+
* Format percent
103+
*
104+
* @param float $percent
105+
*
106+
* @return string
107+
*/
108+
public function formatPercent(float $percent): string
109+
{
110+
/*First rtrim - trim zeros. So, 10.00 -> 10.*/
111+
/*Second rtrim - trim dot. So, 10. -> 10*/
112+
return rtrim(
113+
rtrim(number_format($percent, 2), '0'),
114+
'.'
115+
);
116+
}
96117
}

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)