Tuesday, May 10, 2022

[FIXED] How to display products from subcategory to parent category in opencart?

Issue

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


Solution

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 ;)



Answered By - Ignacio
Answer Checked By - David Goodson (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.