我正在尝试在prestashop 1.7中对product-discounts.tpl中的两个聪明变量进行数学运算,但结果是错误的......
{$product.regular_price}
[输出:12,85€]
{$quantity_discount.discount}
[输出:9.8%]
{$product.regular_price*$quantity_discount.discount}
[输出:117,6]应为:12.85 * 9.8 = 125.93
任何的想法?
我试过了:
{$product.regular_price|floatval}
[输出:12]应该是:12.85
提前致谢
Prestashop 1.7
实际上,这是因为价格为12,85€的逗号,所以,如果你用点替换逗号,那么你将获得正确的值125.93
我认为最简单的解决方案是在tpl文件中分配一个新变量,并用点替换regular_price
12,85中的逗号。
顺便说一下,您也可以用控制器中的点替换逗号,但如果要在模板文件中执行数学运算,可以这样做:
首先,将{$product.regular_price}
分配给regularPrice
变量以及用点替换逗号,如下所示:
{assign var=regularPrice value=$product.regular_price|replace:',':'.'}
我希望$quantity_discount.discount
总是包含点,但如果还有一个逗号而不是点,那么,
{assign var=quantityDiscount value=$quantity_discount.discount|replace:',':'.'}
而且,你要做的最后一件事是将两个变量regularPrice
和quantityDiscount
相互重叠
{assign var=total_price value=$regularPrice * $quantityDiscount}
然后在tpl文件中显示total_price
,如下所示:
{$total_price}
您可以使用以下{$ product.regular_price_amount * $ quantity_discount.discount}
regular_price用于显示价格。如果要进行数学计算,则可以使用产品的regular_price_amount值。