Zen Cart Logo
Forums / General Questions / Which php variable calls for Total Items in Cart?

Which php variable calls for Total Items in Cart?

Locked

Views: 1,596

Results 1 to 9 of 9
This thread is locked. New replies are disabled.
24 Sep 2010, 6:34 PM
#1
samar777 avatar

samar777

Zen Follower

Join Date:
Nov 2009
Location:
Chicago, IL.
Posts:
202
Plugin Contributions:
0

Which php variable calls for Total Items in Cart?

I am trying to do something like this on tpl_shopping_cart_default.php

if ( $cart_quantity == "1" ) {
	echo "Did you know a second box will ship for free!<br />";
}
?>

is that right? When there is only one item in shopping cart, I want to display the message above.

is the variable $cart_quantity right for the number of items in cart?

( My first attempt at php, be gentle )

24 Sep 2010, 7:22 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,081
Plugin Contributions:
56

Re: Which php variable calls for Total Items in Cart?

Assuming that "only one" in the shopping cart means that there's only 1 item of any type/product, then what you want is:

if ($_SESSION['cart']->count_contents() == 1) {
  echo "Did you know a second box will ship for free!<br />";

}

... of course, it's always good practice to put language-specific stuff in a language file! You could add to /includes/languages/english/YOURTEMPLATE/shopping_cart.php:

define('CART_2ND_FOR_FREE', 'Did you know a second box will ship for free!<br />');

and then change your template code to

if ($_SESSION['cart']->count_contents() == 1) {
  echo CART_2ND_FOR_FREE;

}
24 Sep 2010, 7:35 PM
#3
samar777 avatar

samar777

Zen Follower

Join Date:
Nov 2009
Location:
Chicago, IL.
Posts:
202
Plugin Contributions:
0

Re: Which php variable calls for Total Items in Cart?

You are awesome. I have been reading php resources all day to achieve this. Thank you.

It works perfectly.

24 Sep 2010, 7:38 PM
#4
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,081
Plugin Contributions:
56

Re: Which php variable calls for Total Items in Cart?

Glad to help! Good luck with your store.

24 Sep 2010, 7:45 PM
#5
samar777 avatar

samar777

Zen Follower

Join Date:
Nov 2009
Location:
Chicago, IL.
Posts:
202
Plugin Contributions:
0

Re: Which php variable calls for Total Items in Cart?

Yup!

Now, with the same statement how can i put another part in there.

if total items in cart are 3 , display "did you know the 4th box ships free"

and

If total item are more between than 4 but less than 12, " did you know upto 12 boxes ship at no extra charge"

( of course i will use proper text and define files)

24 Sep 2010, 7:56 PM
#6
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,081
Plugin Contributions:
56

Re: Which php variable calls for Total Items in Cart?

Sure, here you go (with 'hard-coded' language):

$itemsInCart = $_SESSION['cart']->count_contents();
if ($itemsInCart == 1) {
  echo "Did you know a second box will ship for free!<br />"; 
} else if ($itemsInCart == 3) {
  echo 'Did you know a fourth box will ship for free!<br />';
} else if ($itemsInCart > 4 && $itemsInCart < 12) {
  echo 'Did you know that up to 12 boxes ship at no extra charge?<br />';
}
24 Sep 2010, 8:13 PM
#7
samar777 avatar

samar777

Zen Follower

Join Date:
Nov 2009
Location:
Chicago, IL.
Posts:
202
Plugin Contributions:
0

Re: Which php variable calls for Total Items in Cart?

That worked really well. thank you. I am going to use some cool images to display instead of the texts. I will send you my site over the weekend to check it out. now off to finding resources to create round edge boxes.

24 Sep 2010, 8:26 PM
#8
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,081
Plugin Contributions:
56

Re: Which php variable calls for Total Items in Cart?

re: round-edge boxes ...

I'm using the jquery.corner functionality (http://jquery.malsup.com/corner/) with good success.

24 Sep 2010, 8:59 PM
#9
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Which php variable calls for Total Items in Cart?

If you can deal with people who have older browsers (basically only IE8 & older) not seeing the rounded cormers, you can get them entirely with CSS in your stylesheet, without adding any HTML divs or javascript etc. All major browsers except IE now support this.```
.yourBoxElement {
-moz-border-radius: tl tr br bl;;
border-radius: tl tr br bl;
border-style: solid;
border-width: 2px;
}

<http://ie.microsoft.com/testdrive/HTML5/01BorderRadius/Default.html>

A good description of how the property works in detail:
<http://www.css3.info/preview/rounded-border/>