题
我需要根据其价格以不同的方式显示一些产品。我希望我可以简单地检查 $price
来自相关主题文件中的变量,但是 $price
包含一个格式的货币字符串。而且,由于OpenCart支持各种货币格式,因此没有简单,强大的方式将价格字符串转换为数字。
我看过产品控制器类, ControllerProductProduct
. 。据我所知,OpenCart不会向视图揭示数字价值。我可以修改控制器类,但我宁愿不是因为它会使更新复杂化。
我忽略了什么吗?是否没有简单的方法可以对OpenCart主题内的价格进行数字比较?
解决方案 2
不幸的是,答案是否定的,OpenCart不会将数字价值公开为主题。您将不得不修改核心文件,哪个 解释如何做.
其他提示
在product.php中查看v1.4.9.4(ControllerProductProduct
)我可以看到以下代码,这些代码设置了您所谈论的$价格的格式值:
if ($discount) {
$price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = $this->currency->format($this->tax->calculate($result['price'],$result['tax_class_id'], $this->config->get('config_tax')));
你为什么不将其更改为以下...
if ($discount) {
$price_num = $this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax'));
$price = $this->currency->format($price_num);
} else {
$price_num = $this->tax->calculate($result['price'],$result['tax_class_id'], $this->config->get('config_tax'));
$price = $this->currency->format($price_num);
然后从中几行,您可以通过添加以下内容将此$ PRICE_NUM值传递给模板:
$this->data['products'][] = array(
'product_id' => $result['product_id'],
...
'price' => $price,
'price_num' => $price_num,
...
应该做你需要的
不隶属于 StackOverflow