ttt2 Posted April 10, 2008 Posted April 10, 2008 I need to get the product count in a category. I came across this function in general.php, but not sure how to use it. It looks like I need to pass category_id into the function. I havn't found how to get category_id. Can any one help? By the way i'm modifying product_listing.php so category_id will change often. function tep_count_products_in_category($category_id, $include_inactive = false){ $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 . "'"); } else { $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 p.products_status = '1' and p2c.categories_id = '" . (int)$category_id . "'"); } $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); } } return $products_count; }
Guest Posted April 10, 2008 Posted April 10, 2008 is this for a report or to be displayed in a store?
ttt2 Posted April 10, 2008 Author Posted April 10, 2008 is this for a report or to be displayed in a store? no, I just need the number to calculate display layout. I installed a add-on that display products in columns and making some enhancement to it. I need the total product number so I can add dividing lines to the cells. Right now, either I have to many dividing lines or too little. I probably making this to complicated. :lol: There are other mods like it, but I like this better. :P
Recommended Posts
Archived
This topic is now archived and is closed to further replies.