OpenCart 主题开发:价格是多少?
我需要根据某些产品的价格以不同的方式展示它们。我希望可以简单地从相关主题文件中检查 $price
变量的值,但 $price
包含货币格式的字符串。由于 OpenCart 支持多种货币格式,因此没有简单、可靠的方法将价格字符串转换回数字。
我查看了产品控制器类 ControllerProductProduct
。据我所知,OpenCart 不会向视图公开数字价格值。我可以修改控制器类,但我不想这样做,因为这会使更新变得复杂。
我是不是忽略了什么?是否没有简单的方法可以在 OpenCart 主题内对价格进行数字比较?
I need to display some products differently depending on their price. I hoped that I could simply check the value of the $price
variable from within the relevant theme file(s), but $price
contains a currency formatted string. And because OpenCart supports a variety of currency formats, there's no simple, robust way of converting price strings back into numbers.
I've looked in the product controller class, ControllerProductProduct
. So far as I can tell, OpenCart does not expose a numeric price value to views. I could modify the controller class, but I'd rather not because it would complicate updates.
Have I overlooked something? Is there no easy way to perform a numeric comparison on a price from within an OpenCart theme?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看product.php (
ControllerProductProduct
) 中的 v1.4.9.4,我可以看到以下代码设置您正在讨论的 $price 的格式化值:为什么不将其更改为如下...
然后再往下几行,您可以通过添加以下内容将此 $price_num 值传递给模板:
应该执行您需要的操作
Looking at v1.4.9.4 in product.php (
ControllerProductProduct
) I can see the following code that sets the formatted value of $price that you're talking about:Why don't you change this to be the following...
And then a few lines down from this, you can then pass on this $price_num value to the template by adding the following:
Should do what you need
不幸的是,答案是否定的,OpenCart 不会向主题公开数字价格值。您必须修改核心文件,Brad 解释了如何操作。
Unfortunately the answer is no, OpenCart does not expose numeric price values to themes. You will have to modify core files, which Brad explains how to do.