Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Newbie question: How to display $product_count


Guest

Recommended Posts

My first post here...Just got OsCommerce installed and using the STS template system.

 

Here is my first problem:

 

User clicks on category link, next page I need to count the number of products within that category and display that number anywhere the page. I found the function that does this, however isn't that a template variable i can setup or existing one that I can just call to the page rather then call this function everytime?

 

 

 

////

// 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;

}

Link to comment
Share on other sites

Then what? My question sounds kinda stupid, but there are other areas where i cant use those oscommerce "/boxes" and I would need to display the product_count total. I just want to access that variable then output to page like <?=$product_count?>

 

What do you recommend besides "turning off" the "show category" counts to false? What does this achieve? Trying to undertand your logic. Explain.

 

Thank you. B)

Link to comment
Share on other sites

Must I setup variables within the product_info.php.html?

 

There seem to be alot of features with OsCommerce however doing the simples things do not appear to be that simple.

Link to comment
Share on other sites

There are several contributions already written to show product quantities. Never saw one for a total count of how many products in a category other than the "Viewing 1-40 of 60 products.

 

Thought maybe you could duplicate this code but alter the text output.

 

In catalog/includes/modules/product_listing.php

This is the code part at the top of the page before the header

<?php
$listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_SEARCH_RESULTS, 'p.products_id');

 if ( ($listing_split->number_of_rows > 0) && ( (PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3') ) ) {
?>

 

then this is where it is called from

<?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?>

 

the text is defined in languages/english so if you changed the line

define('TEXT_DISPLAY_NUMBER_OF_PRODUCTS', 'Displaying <b>%d</b> to <b>%d</b> (of <b>%d</b> products)');

tp

define('TEXT_DISPLAY_NUMBER_OF_PRODUCTS_IN_CAT', '<b>%d</b> products');

 

and change the code on the produccalling the # to

<?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS_IN_CAT); ?>

 

it should work the way I think you want it to. Now how to get this to work on a page itself I am not sure. But maybe this would give you a start? I could be way off here. Not sure what exactly you are trying to do, since osCommerce already posts how many products you have in a category.

Wendy James

 

Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.

Link to comment
Share on other sites

I took a look at your site, how did you get it to display # of items in cart with cart dollar amt total? Do you have the code for that, thats another thing i need.

Link to comment
Share on other sites

You say to look:

 

languages/english

 

for

 

define('TEXT_DISPLAY_NUMBER_OF_PRODUCTS', 'Displaying <b>%d</b> to <b>%d</b> (of <b>%d</b> products)');

tp

define('TEXT_DISPLAY_NUMBER_OF_PRODUCTS_IN_CAT', '<b>%d</b> products');

 

but i cant find that text anywhere in that directory?

 

does anyone know what files i should be looking in?

Link to comment
Share on other sites

This worked for me by calling the tep_count_products_in_category function which is stored in the general.php

 

 

<?

 

$products_in_category = tep_count_products_in_category($catid,$include_inactive = false);

 

if ($products_in_category > 0) {

echo "($products_in_category" . " products)";

} elseif ($products_in_category = 2) {

echo "($products_in_category" . " products)";

} elseif ($products_in_category = 0) {

echo "($products_in_category" . " product)";

}

 

?>

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...