I have a quite detailed tree of categories. As result, products are placed in categories 3 level deep from root not counted and there is (0) on the main page.
I found code what does this calculation and it looking only for products in base and in it's child category, but doesn't going any deeper.
I'm not so good in SQL, so this makes me have headache. Anybody can help me to fix it? It would be enough to count products in child categories two levels deep.
/**
* Shows the Number of Products in category $category_id
*
* @param int $category_id
* @return string The number in brackets
*/
function products_in_category( $category_id ) {
if( PSHOP_SHOW_PRODUCTS_IN_CATEGORY == '1' || vmIsAdminMode() ) {
$num = ps_product_category::product_count($category_id);
if( empty($num) && ps_product_category::has_childs( $category_id )) {
$db = new ps_DB;
$q = "SELECT category_child_id FROM #__{vm}_category_xref ";
$q .= "WHERE category_parent_id='$category_id' ";
$db->query($q);
while( $db->next_record() ) {
$num += ps_product_category::product_count($db->f("category_child_id"));
}
}
return " ($num) ";
}
else
return ( "" );
}