¿Cómo mostrar productos de la subcategoría a la categoría principal en opencart?

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

preguntado el 28 de agosto de 12 a las 14:08

6 Respuestas

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

Respondido 14 Feb 18, 12:02

This is really helpful. simple solution, great impact for user experience. - Yuda Prawira

Just to clarify, this modifies the core files of OpenCart, which is rather nasty. Not that working with vQmod is not ugly as hell as well... - Ignacio

Great Solution. Thank You Sir - Amir Keshavarz

I agree, worked nicely even in the newer versions (, the var name just changed to $filter_data, it's at the line 170. - giovannipds

I'm sorry @IvanStin, this Q is quite old and says I'm using v1.5.3.1. Perhaps someone from the community can check 2.3 - Ignacio

Another solution, rather than modifying the core files directly, is to use vqmod to modify the file for you. That way when you upgrade to a new version, you won't have to re-install any custom modifications you've made.

Below is an the code you'd use to accomplish this in vQmod:

<?xml version="1.0" encoding="UTF-8"?>
    <id>Display products in sub-categories while browsing a parent category</id>
    <author>Jay Williams - jay@myd3.com</author>
    <file name="catalog/controller/product/category.php">
            <search position="after"><![CDATA['filter_category_id' => $category_id,]]></search>
            <add><![CDATA['filter_sub_category' => true,]]></add>

Fuente: https://gist.github.com/jaywilliams/8044763

Respondido el 19 de diciembre de 13 a las 19:12


For Opencart Version, the solution of Ignacio works fines as well just that:

$data (of version 1.5.x) ahora se llama

$filter_data (line #169)

Then just add the line

'filter_sub_category' => true,

after line #170 ('filter_category_id' => $category_id,)

¡Gracias Ignacio!

contestado el 11 de mayo de 16 a las 09:05

the vqmod method is the best and works easily. just add that file and anything.xml and place it in vqmod > xml

Respondido el 17 de enero de 14 a las 01:01

Just contributing with one more information, newest versions uses "ocmod", OpenCart's own vqmod feature. It can work the same way through there.

contestado el 16 de mayo de 16 a las 04:05

For Opencart 3.x: ./catalog/controller/product/category.php


'filter_category_id' => $category_id,

add after:

'filter_sub_category' => true,

After change file, go to "Modification" and "Clear" and "Update" button click

respondido 18 nov., 19:12

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.