简体   繁体   中英

How to get all products from category with any price in OpenCart?

$data = array(
        'filter_category_id'  => $category_id,
    );

    $products = $this->model_catalog_product->getProducts($data);

This is what I use to get all products by category ID.

I am developing a price slider for OpenCart 1.5.6 and I've noticed that whenever I do a query with a selected price range, the method above also gives me results in that price range.

What I need is to get all products from a specific category despite the price every time. How do I do this?

Finally got it working:

$products = $this->db->query("
SELECT p.price, ptc.*, ps.price as special 
FROM " . DB_PREFIX ."product p 
LEFT JOIN " . DB_PREFIX ."product_to_category ptc 
ON p.product_id = ptc.product_id 
LEFT JOIN " . DB_PREFIX ."product_special ps
ON p.product_id = ps.product_id
WHERE ptc.category_id ='$category_id'")->rows;

Using this query I always get all products from the specific category. (also included few other options to get special price).

Hope it will be useful for someone!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM