Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / How do I put a Shopping Cart link in my header?

How do I put a Shopping Cart link in my header?

Views: 1,592

Results 1 to 13 of 13
21 Jun 2011, 2:35 AM
#1
jgraphics avatar

jgraphics

New Zenner

Join Date:
Oct 2006
Posts:
75
Plugin Contributions:
0

How do I put a Shopping Cart link in my header?

I've added a "shopping cart icon" image to the far right of my header_bg.jpg. I need to make the area over the shopping cart icon a link to the shopping cart page. Any help would be greatly appreciated. Thanks in advance.

21 Jun 2011, 4:17 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: How do I put a Shopping Cart link in my header?

in your <a href> for it, set the href="<?php echo zen_href_link(FILENAME_SHOPPING_CART); ?>"

21 Jun 2011, 4:11 PM
#3
jgraphics avatar

jgraphics

New Zenner

Join Date:
Oct 2006
Posts:
75
Plugin Contributions:
0

Re: How do I put a Shopping Cart link in my header?

DrByte:

in your <a href> for it, set the href="<?php echo zen_href_link(FILENAME_SHOPPING_CART); ?>"

Hi Dr.Byte,
Thanks for the quick response.
3 Questions:
1.) Which file do I add the <a href>
2.) Is there a way to make just the right side of the header_bg.jpg image a "link hot spot" (just where I have the cart icon)
3.) Or... do I need to now have three images in my header (logo, header_bg, and a 3rd cart_icon.jpg)

Thanks for all the help.

21 Jun 2011, 4:24 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: How do I put a Shopping Cart link in my header?

  1. It depends on what you've done to your template. Most of the time it's in your custom version of tpl_header.php. Indeed that's where the "Shopping Cart" link is located on a clean install using the default template once someone adds something to their cart.
  2. That would require using an "image map" ... a rather more complicated method than using a specific clickable image.
  3. That's more in line with how the default template works, yes.
21 Jun 2011, 5:53 PM
#5
jgraphics avatar

jgraphics

New Zenner

Join Date:
Oct 2006
Posts:
75
Plugin Contributions:
0

Re: How do I put a Shopping Cart link in my header?

Wow, this is tougher than I thought it would be.
I created an image called "cart_logo.jpg" and I haven't even been able to get it to show up in the header area.

21 Jun 2011, 7:33 PM
#6
jgraphics avatar

jgraphics

New Zenner

Join Date:
Oct 2006
Posts:
75
Plugin Contributions:
0

Re: How do I put a Shopping Cart link in my header?

I did manage to get the shopping cart icon up into the header area and it even links to the shopping cart...:clap:
It is not located where I hoped I could place it.
Right now, it is just right of my logo.jpg and I would like it just right of my header_bg.jpg

This is what I did to get the shopping cart icon up into the header:

Added defines to my header.php file:
define('HEADER_CART_TEXT', 'View My Shopping Cart');
define('HEADER_CART_WIDTH', '107px');
define('HEADER_CART_HEIGHT','106px');
define('HEADER_CART_IMAGE','cart_logo.jpg');

Added this line of code to my tpl_header.php file

<div id="cart_logo"><?php echo '<a href="http://www.mysite.com/index.php?main_page=shopping_cart">' . zen_image($template->get_template_dir(HEADER_CART_IMAGE, DIR_WS_TEMPLATE, $current_page_base,'images'). '/' . HEADER_CART_IMAGE, HEADER_CART_TEXT) . '</a>'; ?></div>

(All edits were made to my custom files... didn't wreck my origianl ZenCart files)

I'm not sure if this was the correct way of adding a shopping cart icon image to my header but it did get one there.
Again, I'm not happy with its location and would like it moved over to the right side of the page, just after the header_bg.jpg

Any help is greatly appreciated.

21 Jun 2011, 8:58 PM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: How do I put a Shopping Cart link in my header?

You could use CSS to position the #cart_logo content where you want it.

21 Jun 2011, 9:47 PM
#8
gowzel avatar

gowzel

New Zenner

Join Date:
Jun 2011
Posts:
41
Plugin Contributions:
0

Re: How do I put a Shopping Cart link in my header?

I have just spent the best part of teaching myself how to do this and finally succeeded.
The images are stored in templates/CUSTOM FOLDER/images
I edited the tpl_header and placed the following code after the log in code:

<?php if ($_SESSION['cart']->count_contents() == 0) { ?>
  <li><?php echo zen_image(DIR_WS_TEMPLATES . $template_dir . '/images/cart_empty_icon.gif','cart empty'); ?> Your cart is empty </li>
<?php
  } else {
if ($_SESSION['cart']->count_contents() != 0) { ?>
  <li><?php echo zen_image(DIR_WS_TEMPLATES . $template_dir . '/images/cart_full_icon.gif','cart full'); ?><a href="<?php echo zen_href_link(FILENAME_SHOPPING_CART, '', 'NONSSL'); ?>"><?php echo HEADER_TITLE_CART_CONTENTS; ?> - <? echo $_SESSION['cart']->count_contents();?> item(s) - <? echo $currencies->format($_SESSION['cart']->show_total());?></a> | </li>
<li><a href="<?php echo zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'); ?>"><?php echo HEADER_TITLE_CHECKOUT; ?></a></li>
21 Jun 2011, 9:54 PM
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: How do I put a Shopping Cart link in my header?

gowzel,
It is recommended to NOT use the <? shorthand. Much safer to use the <?php to be specific. Many webservers don't allow use of short-tags such as <? alone.

21 Jun 2011, 11:16 PM
#10
jgraphics avatar

jgraphics

New Zenner

Join Date:
Oct 2006
Posts:
75
Plugin Contributions:
0

Re: How do I put a Shopping Cart link in my header?

Yep, that did it.
#cart_logo{
float:right
}

Thanks again.

21 Jun 2011, 11:53 PM
#11
gowzel avatar

gowzel

New Zenner

Join Date:
Jun 2011
Posts:
41
Plugin Contributions:
0

Re: How do I put a Shopping Cart link in my header?

Dr Byte, Thanks for your answer, but you've lost me !!! I thought my code was <?php I cannot see where I have put <?

And did you put my code in the scrollable box, but cannot see how to

Thanks

21 Jun 2011, 11:59 PM
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: How do I put a Shopping Cart link in my header?

You used:```
...[B]<? e[/B]cho $_SESSION['cart']->count_contents();?> item(s) - [B]<? e[/B]cho $currencies->format($_SE...

22 Jun 2011, 1:08 AM
#13
gowzel avatar

gowzel

New Zenner

Join Date:
Jun 2011
Posts:
41
Plugin Contributions:
0

Re: How do I put a Shopping Cart link in my header?

Aha, so I did, well spotted, only checked it about 20 times and still didn't see it. Its so easy to make simple mistakes.

Thanks.