mysql查询错误opencart过滤价格

时间:2015-06-15 20:00:53

标签: php mysql opencart opencart2.x

我正在为opencart 2.0创建过滤器模块 这是我的代码:
model / catalog / product.php
function 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'

1 个答案:

答案 0 :(得分:0)

在sql

中的WHERE语句之前添加以下内容
LEFT JOIN " . DB_PREFIX . "product_special p2s ON p.product_id = ps.product_id LEFT JOIN " . DB_PREFIX . "product_discount p2d ON p.product_id = pt.product_id

然后在sql上使用'special'作为'p2s.special'和'discount'作为'p2d.discount'