You are here:  » Product count in Categories A-Z


Product count in Categories A-Z

Submitted by MikeyC on Thu, 2009-01-01 14:14 in

David,

First of all, HAPPY NEW YEAR !

How can i add the product count on my categories A-Z page ?

Mike

Submitted by support on Thu, 2009-01-01 15:50

Hi Mike,

HNY to you too! In categories.php, look for the following code on line 16:

$item["name"] = $product["category"];

...and REPLACE this with:

$sql = "SELECT COUNT(*) AS productCount FROM `".$config_databaseTablePrefix."products` WHERE category='".database_safe($product["category"])."'";
database_querySelect($sql,$rows2);
$productCount = $rows2[0]["productCount"];
$item["name"] = $product["category"]." (".$productCount.")";

Cheers,
David.

Submitted by MikeyC on Thu, 2009-01-01 22:15

I followed the code on Node 458, but that does not show the product count in my categorie A-Z pages. I only see the brackets.

How do i make the code you posted here show it like Electronics(335)

Submitted by support on Fri, 2009-01-02 07:05

Hi Mikey,

Does the above version on this page work?

Cheers,
David.

Submitted by MikeyC on Fri, 2009-01-02 13:20

Yes it works, but it shows as the product count as Electronics (335)

Submitted by support on Fri, 2009-01-02 13:29

Hi Mikey,

I understand - ok, instead of the replacement code above, replace with this:

$sql = "SELECT COUNT(*) AS productCount FROM `".$config_databaseTablePrefix."products` WHERE category='".database_safe($product["category"])."'";
database_querySelect($sql,$rows2);
$productCount = $rows2[0]["productCount"];
$item["extra"] = "(".$productCount.")";
$item["name"] = $product["category"];

(so the last line is the same as the original)

Then, in includes/atoz.php, look for the following code on line 43:

  print "<p><a href='".$item["href"]."'>".$item["name"]."</a></p>";

...and REPLACE this with:

  print "<p><a href='".$item["href"]."'>".$item["name"]."</a> ".$item["extra"]."</p>";

That should do the trick!

Cheers,
David.

Submitted by MikeyC on Fri, 2009-01-02 13:57

Yep, it worked.
Thanks David.