Jcart - Display variable outside of the cart


I'm using the jcart shopping cart script and want to determine whether the cart is empty outside of the file structure of jcart. The jcart.php (attached) sits within a folder jcart and the file I'm trying to determine whether the cart is empty is up one level. Looking on the jcart support forum (http://conceptlogic.com/jcart/help/viewtopic.php?f=3&t=1163) it suggests adding the following to the jcart file:

public function get_total_quantity() {
  $qty = 0;
  foreach($this->items as $item) {
    $qty += $this->qtys[$item];
  return $qty;

Open in new window

and then adding the following to the external file:

<p>There are <?php $jcart->get_total_quantity(); ?> items in your cart.</p>

Open in new window

This however, doesn't appear to work. I would like to assign the value this produces to a variable so the that:

do this }
do that};

Open in new window

Any help would be greatly appreciated. Thank you
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

greetings  bootneck2222, , ,  Not sure about some of what you are asking about, , but in this line of code -
    There are <?php $jcart->get_total_quantity(); ?> items in your cart.

the PHP part is NOT setup to output anything, you need to have a PHP html output like  echo  in it, like this -
     There are <?php echo $jcart->get_total_quantity(); ?> items in your cart.

You say - "I would like to assign the value this produces to a variable so the that", But you don't give much about what it does?

Anyway , here's my suggestion, up above the output line in the PHP code you might try to have code -
$total = $jcart->get_total_quantity();
if ($total) {
   $cartTotal = 'There are '.$total.' items in your cart.';
   } else {
   $cartTotal = 'ERROR: You must first add Items to your cart';


Open in new window

and then down in the paragraph <p> part have -
      <p><?php echo $cartTotal ?></p>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bootneck2222Author Commented:
Thanks Slick812. It was a long day on Friday. Missing the echo was a schoolboy error. #Doh!

The $cartTotal variable assignment was right on too.

Thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.