【发布时间】:2015-06-15 20:00:52
【问题描述】:
我正在为 opencart 2.0 创建过滤器模块
这是我的代码:
模型/目录/product.php
函数 getProducts()
................................... SOME CODES.............
//Filter products based on slider price range
if ((isset($this->request->get['lower']))&&(isset($this->request->get['higher'])))
{
$sql .= " AND p.price >='". $this->request->get['lower'] ." ' AND p.price <='". $this->request->get['higher'] ."'" ;
}
//Filter products based on price slider
if (!empty($data['filter_manufacturer_id'])) {
$sql .= " AND p.manufacturer_id = '" . (int)$data['filter_manufacturer_id'] . "'";
}
这非常适用于没有特别之处的产品。 但我正在尝试将此代码用于特殊用途。 所以我将我的 SQL 查询更改为:
if ((isset($this->request->get['lower']))&&(isset($this->request->get['higher'])))
{
$sql .= " AND (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END) >='". $this->request->get['lower'] ." ' AND (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END) <='". $this->request->get['higher'] ."'" ;
}
但它不适用于具有特殊性的产品。
我收到此错误:Unknown column 'special' in 'where clause'
【问题讨论】:
-
在
$this->db->query($sql)之前尝试函数error_log($sql)并确保包含特价和折扣的表在查询中(如果您发布结果$sql,我可能会提供帮助这里)
标签: php mysql opencart opencart2.x