Zen Cart Logo
Forums / General Questions / Get $_SESSION['cart'] data on a non-zen page

Get $_SESSION['cart'] data on a non-zen page

Views: 1,172

Results 1 to 7 of 7
6 Feb 2013, 6:59 PM
#1
djdavedawson avatar

djdavedawson

Zen Follower

Join Date:
Jul 2005
Location:
Orlando, Fl
Posts:
343
Plugin Contributions:
0

Get $_SESSION['cart'] data on a non-zen page

I have a page on my site running another open source script that i want to access the Zen cart session from.

This page is not a zen cart page.

Is there a way to do this so I can display cart counts on this other page.

Thanks in advance

~D

6 Feb 2013, 8:28 PM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Get $_SESSION['cart'] data on a non-zen page

Due to sessions security this is almost impossible

6 Feb 2013, 10:12 PM
#3
djdavedawson avatar

djdavedawson

Zen Follower

Join Date:
Jul 2005
Location:
Orlando, Fl
Posts:
343
Plugin Contributions:
0

Re: Get $_SESSION['cart'] data on a non-zen page

Thanks for the quick reply on this.

All i need is the cart count from this here.

$_SESSION['cart']->count_contents()

Is there a way to save this data in a separate cookie or session outside of the Zencart DB Session.

Everything I have tried stores it in the DB.

Thanks Again

6 Feb 2013, 10:15 PM
#4
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Get $_SESSION['cart'] data on a non-zen page

Everything I have tried stores it in the DB

Check your configure.php files for

define('STORE_SESSIONS', 'db');
Change to "none" or "file" see if this helps

none = ''

6 Feb 2013, 10:16 PM
#5
drbyte avatar

drbyte

Sensei

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

Re: Get $_SESSION['cart'] data on a non-zen page

Yes, you could add your own custom code to Zen Cart to have it set another cookie with the information you seek. As long as the cookie's domain name matches the domain shared by both software systems.

6 Feb 2013, 10:17 PM
#6
drbyte avatar

drbyte

Sensei

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

Re: Get $_SESSION['cart'] data on a non-zen page

kobra:

Check your configure.php files for

Change to "none" or "file" see if this helps

none = ''

No. Don't mess with STORE_SESSIONS. That won't help the OP with the matter they're seeking. It will only cause other problems.

7 Feb 2013, 3:07 PM
#7
djdavedawson avatar

djdavedawson

Zen Follower

Join Date:
Jul 2005
Location:
Orlando, Fl
Posts:
343
Plugin Contributions:
0

Re: Get $_SESSION['cart'] data on a non-zen page

Thanks Dr B.,

I got it working.

Question though, Should I be using something different for the expire time?

I used the following code to set the cookie.

setcookie('zenGCT',$_SESSION['cart']->count_contents(),'0','/','www.mydomain.com');

Now on my non-zen pages I can call the value.

echo $_COOKIE['zenGCT'];

I then though it would be a good idea to mask the actual count so I added some math.

setcookie('zenGCT',$_SESSION['cart']->count_contents() * 999,'0','/','www.mydomain.com');

and

echo $_COOKIE['zenGCT'] / 999;

You could set the 999 to whatever you wanted.