If this is your first visit, check our documentation. To post, register or login.
Forums / General Questions / Get $_SESSION['cart'] data on a non-zen page

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

Started by djdavedawson on 6 Feb 2013, 6:59 PM · Views: 1,173

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

Zen-Venom Get Bitten

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 = ''

Zen-Venom Get Bitten

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

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
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.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

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

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
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.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

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.