Hi everyone,
Anyone knows how to display the total number of products when we see the subcategories thumbnail, total number of products for that subcategory.
Any help ?
Thanks
The easiest way is to make a query of the product_to_category table to find how many products are associated with the category.
In "catalog/controller/category.php", around lines 50-60, you should find something similar to the following:-
Insert the commented bits.
Then, in "catalog/language/english/controller/category.php", insert the following:-
Then, in "catalog/template/default/content/category.tpl" insert the following:-
below the thumbnail.
That should give you something like what you're after.
EDIT
The "$num_products" query in the above will count ALL products associated with the category, whether the product is enabled or not. Change the query to the following to count only those that are enabled:-
Fido-X.
In "catalog/controller/category.php", around lines 50-60, you should find something similar to the following:-
Code: Select all
$results = $database->getRows("select * from category c left join category_description cd on (c.category_id = cd.category_id) left join image i on (c.image_id = i.image_id) where c.parent_id = '" . (int)(!$request->get('path') ? '0' : (int)end(explode('_', $request->get('path')))) . "' and cd.language_id = '" . (int)$language->getId() . "' order by sort_order");
foreach ($results as $result) {
// count products in category inserted by Fido-X
$num_products = $database->countRows("select * from product_to_category where category_id = '" . (int)$result['category_id'] . "'");
// end of insert
$category_data[] = array(
// inserted by Fido-X
'product_count' = > $num_products,
// end of insert
'name' => $result['name'],
'description' => html_entity_decode($result['description']),
'href' => $url->href('category', FALSE, array('path' => ($request->get('path')) ? $request->get('path') . '_' . $result['category_id'] : $result['category_id'])),
'thumb' => $image->resize($result['filename'], $config->get('config_image_width'), $config->get('config_image_height'))
);
}
$view->set('categories', $category_data);
// inserted by Fido-X
$view->set('text_count', $language->get('text_count'));
// end of insert
Then, in "catalog/language/english/controller/category.php", insert the following:-
Code: Select all
$_['text_count'] = 'Products in Category: ';
Code: Select all
<?php echo $text_count; ?><?php echo $category['product_count']; ?>
That should give you something like what you're after.
EDIT
The "$num_products" query in the above will count ALL products associated with the category, whether the product is enabled or not. Change the query to the following to count only those that are enabled:-
Code: Select all
$num_products = $database->countRows("select * from product_to_category p2c left join product p on p2c.product_id = p.product_id where p.status = '1' and p2c.category_id = '" . (int)$result['category_id'] . "'");
Last edited by fido-x on Tue Nov 11, 2008 6:08 pm, edited 1 time in total.
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool
If you're not living on the edge ... you're taking up too much space!
Who is online
Users browsing this forum: No registered users and 6 guests