Shoppingcart/Freeship in Header support
Shoppingcart/Freeship in Header has been submitted to Free Addons and should be available soon.
This mod will give you a box in your header which shows the number of items in the cart, the total amount if any items in cart, the amount required to qualify for free shipping, and a checkout button if any items in cart.
You can set its position and style by editing your stylesheet with rules suggested in the readme.
Compatible with multiple languages.
Re: Shoppingcart/Freeship in Header support
Very cool mod! Great, absolutely great readme file with clear and precise instructions and info - and here is the bonus, its not a text file!
The only thing that I would like to customize about it is, I would like to format it into 2 columns. The first column being the # of items on the first row and the second row, the Total Price. On the second column on the first row is where I want to place the View Cart button.
Can I do that via css? How? I'm a bit of a novice when it comes to css, so if someone can provide some example code, awesome!
Re: Shoppingcart/Freeship in Header support
Rearranging the box layout into columns as you describe, and adding a separate View Cart button that is always on instead of a link on the count when full, is beyond the capacities of CSS and will require a bit of restructuring of code.
Find this section in tpl_cart_header.php
PHP Code:
<div id="cartCount">
<?php
$cart_count = $_SESSION['cart']->count_contents();
if ($cart_count) {
$_SESSION['cart']->get_products();
$basket_total = $_SESSION['cart']->show_total();
echo '<span id="cartTotal">' . CART_HEADER_TOTAL . $currencies->format($basket_total) . '</span>' ;
}
echo ($cart_count? '<a href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '" title="' . CART_HEADER_TITLE . '">':'') . CART_HEADER_IN_CART_PRE . $cart_count . (($cart_count == 1)? CART_HEADER_IN_CART_SINGULAR: CART_HEADER_IN_CART_PLURAL) . ($cart_count? '</a>': '');
?>
</div>
Add
echo '<a id="cartButton" href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '" title="' . CART_HEADER_TITLE . '"><img src="yourimagesource.gif" /></a>': '');
to get
PHP Code:
<div id="cartCount">
<?php
$cart_count = $_SESSION['cart']->count_contents();
if ($cart_count) {
$_SESSION['cart']->get_products();
$basket_total = $_SESSION['cart']->show_total();
echo '<span id="cartTotal">' . CART_HEADER_TOTAL . $currencies->format($basket_total) . '</span>' ;
}
echo ($cart_count? '<a href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '" title="' . CART_HEADER_TITLE . '">':'') . CART_HEADER_IN_CART_PRE . $cart_count . (($cart_count == 1)? CART_HEADER_IN_CART_SINGULAR: CART_HEADER_IN_CART_PLURAL) . ($cart_count? '</a>': '');
?>
</div>
<?php echo '<a id="cartButton" href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '" title="' . CART_HEADER_TITLE . '"><img src="yourimagesource.gif" /></a>': ''); ?>
You would also want more <span> elements to control the qty and total.
Then style as required:
Code:
/*Shoppingcart/Freeship in Header*/
#headerWrapper {position: relative;}
#cartHeader {
width: 30em;/*17em*/
position: absolute;
top: 0.1em;/*4.0em*/
right: 2.0em;
/*bottom:0.1em;/*added*/
background: #cacaca;
color: #000000;
border: 1px solid #888888;
}
#cartHeader h3 {
display: none;/*added*/
/*text-align: center;*/
/*color: #005599;/*added*/
/*margin:0.1em 0;/*added*/
}
#cartCount {
/*border-top: 1px solid #999999;*/
text-align: left;/*center*/
padding: 0.5em 0;/*added*/
float: left;
}
#cartCount a {)
#cartTotal {}
#cartFreeShip {
margin: 0 0.3em;
}
#cartCheckout {
float: left;/*right*/
margin: 0.3em;
}
#cartButton {
display: block;
float: right;
width: 123px; /*adjust to fit*/
}
I do think it's better not to have links to the cart and checkout if there is nothing in the cart.
Re: Shoppingcart/Freeship in Header support
PHP Code:
<div id="cartCount">
<?php
$cart_count = $_SESSION['cart']->count_contents();
echo ($cart_count? '<a href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '" title="' . CART_HEADER_TITLE . '">':'') . CART_HEADER_IN_CART_PRE . $cart_count . (($cart_count == 1)? CART_HEADER_IN_CART_SINGULAR: CART_HEADER_IN_CART_PLURAL) . ($cart_count? '</a>': '');
?>
</div>
if ($cart_count) {
$_SESSION['cart']->get_products();
$basket_total = $_SESSION['cart']->show_total();
echo '<div id="cartTotal">' . CART_HEADER_TOTAL . $currencies->format($basket_total) . '</div>' ;
}
<?php echo '<a id="cartButton" href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '" title="' . CART_HEADER_TITLE . '"><img src="yourimagesource.gif" /></a>': ''); ?>
Code:
#cartTotal {
float: left;
}
Re: Shoppingcart/Freeship in Header support
Thanks for the reply.
I copied that line of code and put it at the bottom of my tpl_cart_header page and then refreshed FF and the page came up blank, all it shows is my header background color and my logo image at the left corner. Everything under the header area is gone.
It seems in your post that extra line of code is to be placed at the bottom of the file, correct?
The reason why I know its this particular line of code causing the problem is that my site was fine before, any help is greatly appreciated!
Re: Shoppingcart/Freeship in Header support
Oops - forgot to wrap php tags around the relocated code. Since its new location is outside the original php section, it needs those for itself.
PHP Code:
<div id="cartCount">
<?php
$cart_count = $_SESSION['cart']->count_contents();
echo ($cart_count? '<a href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '" title="' . CART_HEADER_TITLE . '">':'') . CART_HEADER_IN_CART_PRE . $cart_count . (($cart_count == 1)? CART_HEADER_IN_CART_SINGULAR: CART_HEADER_IN_CART_PLURAL) . ($cart_count? '</a>': '');
?>
</div>
<?php if ($cart_count) {
$_SESSION['cart']->get_products();
$basket_total = $_SESSION['cart']->show_total();
echo '<div id="cartTotal">' . CART_HEADER_TOTAL . $currencies->format($basket_total) . '</div>' ;
} ?>
<?php echo '<a id="cartButton" href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '" title="' . CART_HEADER_TITLE . '"><img src="yourimagesource.gif" /></a>': ''); ?>
I have attached the zip file here until the mod is activated in Free Addons.
Re: Shoppingcart/Freeship in Header support
Glenn,
I love the idea. I tried your last piece of code but no luck... "500 - Internal server error" is was i get.
The original code works, it's the mod above that crashes the page.
Not sure why, my php skills are still close to none. :blush:
It's that part that cause the error:
PHP Code:
<?php echo '<a id="cartButton" href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '" title="' . CART_HEADER_TITLE . '"><img src="whatever.png" /></a>': ''); ?>
Any idea on what's missing?
Thanks for your help and support on Zen Cart. Love your "Smart Background" add-on btw.
Re: Shoppingcart/Freeship in Header support
Ack! I was typing in a hurry and missed the last bit that needed to be removed:
: ''
at the end of the statement. This will work:
PHP Code:
<?php echo '<a id="cartButton" href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '" title="' . CART_HEADER_TITLE . '"><img src="whatever.png" /></a>'); ?>
Re: Shoppingcart/Freeship in Header support
Re: Shoppingcart/Freeship in Header support
"I have also the slovenian language, wich don't have only singular and plural.
Should be like that:
1 item in card- Izdelek
2 items in card- Izdelka
3 items in card- Izdelki
4 items in card- Izdelki
5 items in card- Izdelkov
6 items in card- Izdelkov
7 items in card- Izdelkov.......( and so on, the same)"
What would be the word for zero or no items in cart?
Edit /includes/templates/your_template/templates/tpl_cart_header.php.
PHP Code:
echo ($cart_count? '<a href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '" title="' . CART_HEADER_TITLE . '">':'') . CART_HEADER_IN_CART_PRE . $cart_count . (($cart_count == 1)? CART_HEADER_IN_CART_SINGULAR: CART_HEADER_IN_CART_PLURAL) . ($cart_count? '</a>': '');
Replace
(($cart_count == 1)? CART_HEADER_IN_CART_SINGULAR: CART_HEADER_IN_CART_PLURAL)
with
$cart_header_number
PHP Code:
echo ($cart_count? '<a href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '" title="' . CART_HEADER_TITLE . '">':'') . CART_HEADER_IN_CART_PRE . $cart_count . $cart_header_number . ($cart_count? '</a>': '');
Add just above that
PHP Code:
switch ($cart_count){
case '0':
$cart_header_number = CART_HEADER_IN_CART_QTY_0;
break;
case '1':
$cart_header_number = CART_HEADER_IN_CART_QTY_1;
break;
case '2':
$cart_header_number = CART_HEADER_IN_CART_QTY_2;
break;
case '3':
$cart_header_number = CART_HEADER_IN_CART_QTY_3_4;
break;
case '4':
$cart_header_number = CART_HEADER_IN_CART_QTY_3_4;
break;
default:
$cart_header_number = CART_HEADER_IN_CART_QTY_5;
break;
}
Then in cart_header_defines.php, add these lines:
PHP Code:
define{'CART_HEADER_IN_CART_QTY_0','Izdelek');//???word to use here???
define{'CART_HEADER_IN_CART_QTY_1','Izdelek');
define{'CART_HEADER_IN_CART_QTY_2','Izdelka');
define{'CART_HEADER_IN_CART_QTY_3_4','Izdelki');
define{'CART_HEADER_IN_CART_QTY_5','Izdelkov');