1

I am creating filter module for opencart 2.0 Here is my code:
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'] . "'";
        }

This works great for products don't have special. But i am trying to apply this code for special. So I am changing my SQL query to this:

    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'] ."'" ;
    }

But it don't works for products which have special.

I got this error: Unknown column 'special' in 'where clause'

2

1 Answer 1

0

Add following before WHERE statement in sql

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

then use 'special' as 'p2s.special' and 'discount' as 'p2d.discount' on sql

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.