How to display products from subcategory to parent category in opencart?

Aaviya picture Aaviya · Aug 28, 2012 · Viewed 23.4k times · Source

I'm trying to find a solution but still no luck. I want to display all products from subcategories to parent category.

I'm using Opencart 1.5.3.1

Answer

Nacho picture Nacho · Oct 25, 2012

After reading the source, I figured it out:

In catalog/controller/product/category.php (or wherever you're calling function model_catalog_product->getProducts) you have to add filter_sub_category = true:

$data = array(
    'filter_category_id' => $top_category,
    'filter_sub_category' => true,
    'sort'               => $sort,
    'order'              => $order,
    'start'              => ($page - 1) * $limit,
    'limit'              => $limit
);

$product_total = $this->model_catalog_product->getTotalProducts($data);

Make sure you check the other answers if you're using a later version ;)