如何在OpenCart产品控制器中添加新变量?
我坚持了一个OpenCart问题,它是旧版本1.5.6.4。 我想在产品页面上显示最低特价。
首先,我在模型中使用SQL查询创建了一个函数:
public function getSpecialPriceMin($product_id) {
$query = $this->db->query("SELECT MIN(price) FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "'");
return $query->row;
}
然后,我尝试将结果保存在产品控制器中的变量中(因为我收到错误消息不确定的变量而没有成功):
$data['myVariable'] = $this->model_catalog_product->getSpecialPriceMin($product_id);
然后我尝试回声产品页面:
<?php echo $myVariable; ?>
我感谢任何帮助。先感谢您。
I stuck with an Opencart issue, it is old version 1.5.6.4.
I want to show the lowest special price on the product page.
Firstly I created a function in the model with the SQL query:
public function getSpecialPriceMin($product_id) {
$query = $this->db->query("SELECT MIN(price) FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "'");
return $query->row;
}
Then I tried to save the result in a variable in the product controller (without success as I am receiving an error message undefined variable):
$data['myVariable'] = $this->model_catalog_product->getSpecialPriceMin($product_id);
And then I try to echo the variable on the product page:
<?php echo $myVariable; ?>
I would appreciate any help. Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果使用OC 1.5.xx版本,则应使用:
在模型文件中:
控制器:
然后您可以在产品页面上回声:
If you use OC 1.5.x.x version you should use:
in model file:
Controller:
And then you can to echo the variable on product page: