Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Product count....


ComicWisdom

Recommended Posts

I have modified the index.php file to display the count of products available under the catagory graphic and beside the product name.

 

However, if a product has recently sold out and been deactivated, it still counts the product and then customers go to the sub-category listing expecting to find four products and instead find maybe one or none.

 

Here is my code modification:

 

//ADDED FOR PRODUCTS COUNT IN SUB-CATEGORY
	  $categories_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = " . $categories['categories_id']);
	  $cateqories_products = tep_db_fetch_array($categories_products_query);
//END 
  $rows++;
  $cPath_new = tep_get_path($categories['categories_id']);
  $width = (int)(100 / MAX_DISPLAY_CATEGORIES_PER_ROW) . '%';
//ADDED $cateqories_products['total'] TO FOLLOWING LINE TO DISPLAY PRODUCTS COUNT IN SUB-CATEGORY WITH PRODUCTS NAME 
  echo '				<td align="center" class="smallText" width="' . $width . '" valign="top"><a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . tep_image(DIR_WS_IMAGES . $categories['categories_image'], $categories['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br>' . $categories['categories_name'] . ' — ' . $cateqories_products['total'] .'</a></td>' . "\n";
  if ((($rows / MAX_DISPLAY_CATEGORIES_PER_ROW) == floor($rows / MAX_DISPLAY_CATEGORIES_PER_ROW)) && ($rows != $number_of_categories)) {
	echo '			  </tr>' . "\n";
	echo '			  <tr>' . "\n";
  }
}

 

Could someone suggest a change that would correct this so that sold out/deactivated products would not be counted?

 

Thank you,

 

Ralph

Just between us, remember there are only 10 kinds of people in the world; those who understand binary and those who don't!!

 

Remember, learning is a "do-it-yourself" experience; although, not necessarily a "do-it-BY-yourself" experience.

 

The quickest way to learn is to forget to BACKUP!

Link to comment
Share on other sites

I imagine that I would have to do some kind of cross-query here including

 

WHERE p.products_quantiy > 0

 

but I'm not quite sure how to phrase that.

 

Sitll working on it,

 

Ralph

Just between us, remember there are only 10 kinds of people in the world; those who understand binary and those who don't!!

 

Remember, learning is a "do-it-yourself" experience; although, not necessarily a "do-it-BY-yourself" experience.

 

The quickest way to learn is to forget to BACKUP!

Link to comment
Share on other sites

Wouldn't you want to first do a query to only find active products with positive quantities?

 

Something like

SELECT products_id FROM products WHERE products_quantity > 0 AND products_status

 

Then you can use those id numbers to cross-reference the products_to_categories table.

Do, or do not. There is no try.

 

Order Editor 5.0.6 "Ultra Violet" is now available!

For support or to post comments, suggestions, etc, please visit the Order Editor support thread.

Link to comment
Share on other sites

Hi Ralph, this function already exists in your general.php... you only need to call it. Normally built into your categories box (know those nasty numbers in brackets?)

 

////
// 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) {
$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;
 }

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...