HOW TO: show number of products in cart

By | January 24, 2008

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 thoughts on “HOW TO: show number of products in cart

  1. Rick

    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?

Leave a Reply

Your email address will not be published.