About Club osCommerce

Showcasing osCommerce…the good, the bad and the ugly!

StumbleUpon It! DIGG It!

HOW TO: show number of products in cart

Written By Gary on Jan 24 2008 · Comments (3)

Buy Gary A Beer?
Buying me a "beer" helps me to keep my contributions updated and keep this blog alive - and you get a link from my homepage to your site. Cheers!


Shwoing the number of products in osCommerce cart is very simple;

echo $cart->count_contents();

This will show the total number of items in a persons cart.

You can go further with this and say something like;

You have <?php echo $cart->count_contents(); ?> items in your cart.

But this will not be grammatically correct if only 1 item is in the cart, In this case we say;

You have <?php echo $cart->count_contents(); ?> <?php echo $cart->count_contents() == "1" ? "item " : "items " ; ?> in your cart.

Now the code will determine whether to say "item" or "items" depending upon the number of items in the cart.

ENJOY!

3 Comments

  1. When I attempt to create an acount I get the following error:
    1054 – Unknown column 's.public_flag' in 'where clause'

    select count(*) as total from orders o, orders_status s where o.customers_id = '866' and o.orders_status = s.orders_status_id and s.language_id = '1' and s.public_flag = '1'

    [TEP STOP]

    Any thoughts?

    Comment by Rick — June 29, 2008 @ 7:05 am


  2. Rick – http://svn.oscommerce.com/jira/browse/OSC-495

    Comment by Gary — June 29, 2008 @ 8:12 am


  3. Great easy tip!

    Comment by Keith — April 1, 2009 @ 6:25 pm


Leave a comment

RSS feed for comments on this post · TrackBack URL

Hot 100 osCommerce Shops

View the osCommerce HOT 100These are the best looking, most exceptional osCommerce Stores as voted for by you.

New to osCommerce - get inspiration from these beautiful shops. Reckon your site has what it takes to become a member of the HOT 100? Submit it!