Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Showing Cart Quantity

Showing Cart Quantity

Locked

Views: 917

Results 1 to 6 of 6
This thread is locked. New replies are disabled.
26 Feb 2010, 8:47 PM
#1
still_learning avatar

still_learning

New Zenner

Join Date:
Jan 2010
Posts:
18
Plugin Contributions:
0

Showing Cart Quantity

I would like to show the quantity that is in my cart on every page, which you would think would be the easiest thing in the world beings that this is shopping cart software, but I cannot seem to figure out any way to do it. I realize it must be using a SESSION variable. I was able to get it to echo the quantity for individual products, which is weird. For instance, if I clicked on a certain product, then it would echo the contents of the cart, BUT ONLY for that product. If there were 10 products in the cart and 4 of them were for that product, then the shopping cart would say "4 items in cart."

I tried this code and it printed nothing:

$totalsDisplay = TEXT_TOTAL_ITEMS . $_SESSION['cart']->count_contents();

echo $totalsDisplay;

What am I missing here?

26 Feb 2010, 11:12 PM
#2
still_learning avatar

still_learning

New Zenner

Join Date:
Jan 2010
Posts:
18
Plugin Contributions:
0

Re: Showing Cart Quantity

For anyone looking to do this little trick, I finally figured it out. I hate spending 3 hours on something so little....but anyways.

Originally I was starting my session like you normally would by using session_start() like this:

session_start()
$cart_quantity = $_SESSION['cart']->count_contents();
echo $cart_quantity;

This for whatever reason does not work. However, declaring the session array by itself ($_SESSION); manages to start the session. I have no idea why this is the way it is, but the code below works.

($_SESSION);
$cart_quantity = $_SESSION['cart']->count_contents();
echo $cart_quantity;

So if you just want a little line of text at the top of your page that says "Items In Cart: 3 items", you can do so by using this session variable.

26 Feb 2010, 11:29 PM
#3
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Showing Cart Quantity

Or you could just use/adapt one of the cart summary sidebox or header mods which are already available...
Shoppingcart/Freeship in Header has logic built in to switch between singular and plural, so it will say "0 items", "1 item", "2 items", as appropriate.

And there is no need to initialize a session, as that is already done. All you need to do is output the value of $_SESSION['cart']->count_contents().

26 Feb 2010, 11:47 PM
#4
still_learning avatar

still_learning

New Zenner

Join Date:
Jan 2010
Posts:
18
Plugin Contributions:
0

Re: Showing Cart Quantity

gjh42:

Or you could just use/adapt one of the cart summary sidebox or header mods which are already available...
Shoppingcart/Freeship in Header has logic built in to switch between singular and plural, so it will say "0 items", "1 item", "2 items", as appropriate.

And there is no need to initialize a session, as that is already done. All you need to do is output the value of $_SESSION['cart']->count_contents().

First off, I already tried to do it without initializing a session.....it doesn't work. You would think it would work though, no? Go ahead and try it, it doesn't. Trust me I was pulling my hair out for hours because I kept looking at it and the logic wasn't making any sense.

Secondly, I don't want a sidebox on my website. I wanted to customize my website to look exactly how I wanted it to look (I had my site designed before hand), which was to have my view cart custom button at the top of the page with a piece of text on it that says Items In Cart: (displays quantity). I want all of the functionality of the Zen Cart, but basically zero Zen Cart design.

27 Feb 2010, 12:55 AM
#6
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Showing Cart Quantity

Where are you putting your code? If in tpl_header.php, or called from it, the simple variable works.

And the mod tony_sar mentioned is just a snippet of code that you can put there or wherever you want it.