Zen Cart Logo
If this is your first visit, check our documentation. To post, register or login.
Forums / General Questions / General Questions / getting the total items in the cart to show up elswhere on the page

getting the total items in the cart to show up elswhere on the page

Locked
This thread is locked. New replies are disabled.
13 Feb 2008, 6:04 AM
#1
shyam666 avatar

shyam666

New Zenner

Join Date:
Feb 2008
Posts:
3
Plugin Contributions:
0

Post #1 by shyam666

i am trying to get the total number of items in the shopping cart to show up on the page at all times.. but not sure how...

see the site at
http://202.60.88.114/~obsessed/
it needs to go in a div box in the header underneath the text "your cart"

thanks

16 Feb 2008, 3:11 AM
#2
libragear avatar

libragear

New Zenner

Join Date:
Feb 2008
Posts:
29
Plugin Contributions:
0

Post #2 by libragear

Hi. :) I was also searching for this info and came across this thread tonight.

http://www.zen-cart.com/forum/showthread.php?t=36992&highlight=diplay+number+of+items+in+cart

I used the info down the page a bit. If you want to see it in action here it is all formated:

http://www.libragear.com/zencart/

Hope this helps. Have a great night. :)

Kate

ps. its the post that businesstoweb made on the first page. :)

Kate / Libra Gear
One girl, two pairs of pliers, and a little imagination.

16 Feb 2008, 9:48 AM
#3
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,771
Plugin Contributions:
56

Post #3 by swguy

Have you tried using the shopping cart sidebox?

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

16 Feb 2008, 5:45 PM
#4
libragear avatar

libragear

New Zenner

Join Date:
Feb 2008
Posts:
29
Plugin Contributions:
0

Post #4 by libragear

I hadn't tried it until now because I was curious also. :) So it would seen in order to do that you need to make a custom sidebox. so create a new file and call it something like cart_count.php . You can call it anything really. Save it in includes/modules/sideboxes .

Here is the code for this file, which I found in another thread here:
Custom
Sideboxes

<?php
/**
 * cart_count sidebox - prepares content for the main cart Count sidebox
 *
 * @package templateSystem
 * @copyright Copyright 2003-2005 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: cart_count.php 2718 2005-12-28 06:42:39Z drbyte $
 */

  // test if box should be displayed
  $show_CUSTOM_NAME = true;

  if ($show_CUSTOM_NAME  == true) {
      ?>
            
      <div align="center" style="padding:5px;">

<table class="cart_count_sidebox_main">
<tr><td class="cart_count_sidebox">

Your cart contains:

<?php if ($_SESSION['cart']->count_contents() > 0) {
$products = $_SESSION['cart']->get_products();
echo '<br><a href="/zencart/index.php?main_page=shopping_cart">' . 

$_SESSION['cart']->count_contents().'Item(s) - Total: ';
echo $currencies->format($_SESSION['cart']->show_total());
}
if ($_SESSION['cart']->count_contents() == 0) {
$products = $_SESSION['cart']->get_products();
echo '<br><a href="/zencart/index.php?main_page=shopping_cart"> Item(s) $0.00</a>';
}
?></td></tr></table>
	</div>
      <?php }
?>

You can of course change the text to whatever you want.

And this is the css I used for my table, You are by no means beholden to this. :)

.cart_count_sidebox_main
{
width: 150px;
vertical-align: top;
}

.cart_count_sidebox
{
vertical-align: middle;
text-align: left;
}

If you have any question feel free to contact me. :) Good luck!

Here is a link to it in action My site.. it is at the bottom of

the left column. I wil leave it up for a bit. :)

Kate

Kate / Libra Gear
One girl, two pairs of pliers, and a little imagination.

16 Feb 2008, 5:53 PM
#5
libragear avatar

libragear

New Zenner

Join Date:
Feb 2008
Posts:
29
Plugin Contributions:
0

Post #5 by libragear

I almost forgot, you will need to go to Admin --> Tools --> Layout Box Controller and turn your new box on in whatever column you want it. :)

Kate / Libra Gear
One girl, two pairs of pliers, and a little imagination.

16 Feb 2008, 5:59 PM
#6
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,771
Plugin Contributions:
56

Post #6 by swguy

<a href="/zencart/index.php?main_page=shopping_cart">'

This is a bug. If you ever move the cart, for example, during an upgrade, it will break. And it will break silently, meaning you'll have to spend time testing to find the fault.

The proper way to do this is to use the defines from configure.php that describe the directory hierarchy you're using.

Unless you've taken the time to study the code and understand exactly how it works, the best practice is to use the native cart software facilities where they meet your needs. There could be other bugs in this code, but this one jumped out at me immediately.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

10 Jul 2008, 4:29 PM
#7
tated avatar

tated

New Zenner

Join Date:
May 2008
Posts:
10
Plugin Contributions:
0

Post #7 by tated

swguy,

swguy:

The proper way to do this is to use the defines from configure.php that describe the directory hierarchy you're using.

Could you explain your advice a bit more? I'm very much interested in doing this too, the right way.

thanks,

tated

10 Jul 2008, 11:40 PM
#8
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,771
Plugin Contributions:
56

Post #8 by swguy

This URL:

<a href="/zencart/index.php?main_page=shopping_cart">'

is best built from code using the definitions in configure.php. Here's an example from includes/templates/template_default/common:

<li><a href="<?php echo zen_href_link(FILENAME_SHOPPING_CART, '', 'NONSSL'); ?>"><?php echo HEADER_TITLE_CART_CONTENTS; ?></a></li>

This protects you in case you move the cart during an upgrade, for instance.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.