File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
view/base/templates/product/price Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Catalog \Pricing \Render ;
7
9
8
10
use Magento \Catalog \Model \Product ;
@@ -71,7 +73,9 @@ public function jsonEncode($valueToEncode)
71
73
*
72
74
* @param int $length
73
75
* @param string|null $chars
76
+ *
74
77
* @return string
78
+ * @throws \Magento\Framework\Exception\LocalizedException
75
79
*/
76
80
public function getRandomString ($ length , $ chars = null )
77
81
{
@@ -93,4 +97,21 @@ public function getCanDisplayQty(Product $product)
93
97
}
94
98
return true ;
95
99
}
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
+ }
96
117
}
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ $product = $block->getSaleableItem();
77
77
$ price ['price_qty ' ],
78
78
$ priceAmountBlock ,
79
79
$ index ,
80
- $ tierPriceModel ->getSavePercent ($ price ['price ' ])
80
+ $ block -> formatPercent ( $ price [ ' percentage_value ' ] ?? $ tierPriceModel ->getSavePercent ($ price ['price ' ]) )
81
81
)
82
82
: __ ('Buy %1 for %2 each ' , $ price ['price_qty ' ], $ priceAmountBlock );
83
83
?>
You can’t perform that action at this time.
0 commit comments