Not sure how useful this is to other people, but I missed this little feature, coming from OsCommerce to OpenCart 1.4.9. Out of the box in OsCommerce, when a category has products in it, the number of products appears in brackets beside the category name in navigation. I've edited the source to make the same thing happen for OpenCart (1.4.9).
in catalog\model\catalog\category.php on line 16, there is this line of PHP:
Code: Select all
$category_data = $query->rows;
Code: Select all
// Get the count for the rows that have a count
$count = $this->db->query("SELECT COUNT(*) AS numproducts, p2c.category_id AS newcat FROM " . DB_PREFIX . "_product_to_category p2c GROUP BY p2c.category_id");
$count_data = $count->rows;
// Append the count to the categories that have a count.
foreach($category_data as &$result){
foreach($count_data as &$count_result){
if($result['category_id'] == $count_result['newcat']){
$result['count'] = $count_result['numproducts'];
}
}
}
Code: Select all
if ($this->category_id == $result['category_id']) {
Code: Select all
if ($this->category_id == $result['category_id']) {
$output .= '<a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $new_path) . '"><b>' . $result['name'] . '</b></a>';
if($result['count']){
$output .= ' <b>(' . $result['count'] . ')</b>';
}
} else {
$output .= '<a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $new_path) . '">' . $result['name'] . '</a>';
if($result['count']){
$output .= ' (' . $result['count'] . ')';
}
}

Cheers,
Josh
p.s please bare with my tabbing in the examples, i can't seem to get them right on this forum
