Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions catalog/includes/functions/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ function tep_calculate_tax($price, $tax) {
////
// Return the number of products in a category
// TABLES: products, products_to_categories, categories
function tep_count_products_in_category($category_id, $include_inactive = false) {
function tep_count_products_in_category($category_id, $include_inactive = false, $count_subs = true) {
$products_count = 0;
if ($include_inactive == true) {
$products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$category_id . "'");
Expand All @@ -404,11 +404,13 @@ function tep_count_products_in_category($category_id, $include_inactive = false)
$products = tep_db_fetch_array($products_query);
$products_count += $products['total'];

$child_categories_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$category_id . "'");
if (tep_db_num_rows($child_categories_query)) {
while ($child_categories = tep_db_fetch_array($child_categories_query)) {
$products_count += tep_count_products_in_category($child_categories['categories_id'], $include_inactive);
}
if ($count_subs == true) {
$child_categories_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$category_id . "'");
if (tep_db_num_rows($child_categories_query)) {
while ($child_categories = tep_db_fetch_array($child_categories_query)) {
$products_count += tep_count_products_in_category($child_categories['categories_id'], $include_inactive, $count_subs);
}
}
}

return $products_count;
Expand Down
14 changes: 6 additions & 8 deletions catalog/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@

// the following cPath references come from application_top.php
$category_depth = 'top';

if (isset($cPath) && tep_not_null($cPath)) {
$categories_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'");
$categories_products = tep_db_fetch_array($categories_products_query);
if ($categories_products['total'] > 0) {

if (tep_count_products_in_category($current_category_id, false, false) > 0) {
$category_depth = 'products'; // display products
} else {
$category_parent_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$current_category_id . "'");
$category_parent = tep_db_fetch_array($category_parent_query);
if ($category_parent['total'] > 0) {
}

if (tep_has_category_subcategories($current_category_id)) {
$category_depth = 'nested'; // navigate through the categories
} else {
$category_depth = 'products'; // category has no products, but display the 'no products' message
}
}
}

Expand Down