如何在OpenCart产品控制器中添加新变量?

发布于 2025-02-04 19:29:05 字数 590 浏览 5 评论 0原文

我坚持了一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

呆° 2025-02-11 19:29:05

如果使用OC 1.5.xx版本,则应使用:
在模型文件中:

public function getSpecialPriceMin($product_id) {
$query = $this->db->query("SELECT MIN(price) AS min_price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "'");
return $query->row;
}

控制器:

$query = $this->model_catalog_product->getSpecialPriceMin($product_id);
$this->data['myVariable'] = $query['min_price'];

然后您可以在产品页面上回声:

<?php echo $myVariable; ?>

If you use OC 1.5.x.x version you should use:
in model file:

public function getSpecialPriceMin($product_id) {
$query = $this->db->query("SELECT MIN(price) AS min_price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "'");
return $query->row;
}

Controller:

$query = $this->model_catalog_product->getSpecialPriceMin($product_id);
$this->data['myVariable'] = $query['min_price'];

And then you can to echo the variable on product page:

<?php echo $myVariable; ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文