Forums / Managing Customers and Orders / acces visitor's cart outside zen....

acces visitor's cart outside zen....

Locked

Started by adrian_hs on 27 Feb 2009, 7:58 AM · Views: 2,009

Results 1 to 8 of 8
This thread is locked. New replies are disabled.
27 Feb 2009, 7:58 AM
#1
adrian_hs avatar

adrian_hs

New Zenner

Join Date:
Jul 2008
Posts:
14
Plugin Contributions:
0

acces visitor's cart outside zen....

Hello zenners,

I want to make a fast-command module on my store using ajax ;) .

Since now i managed to acces the visitor's cart from zen files using:

$visitorsCart = $_SESSION['cart'];

which is an object and if you count() you'll find the number of products in cart:

$numberOfProducts = count($_SESSION['cart']->get_products());

So that was the magic.

But i can't see $_SESSION['cart'] outside zen files...

What can i do for that... any developer here to guide me? :blush:

27 Feb 2009, 9:51 AM
#2
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: acces visitor's cart outside zen....

The cart is held in a PHP session array created by Zen Cart. Zen Cart indexes the session array by way of the zenid which is stored in a cookie. To access the session outside of Zen Cart you would need to restart it by passing the ID as GET or POST parameter. This isn't something that I've tried to do, so am hazy on the details.

You may also be able to restart the session by name. I'm not sure whether you would have give the session a name while in Zen Cart or whether this is something already allocated and retrievable from the cookie.

Sorry to be vague. Not something that I've tried before and I'd recommend spending some time in the sessions section of the PHP manual. I'll be interested to hear how you get on.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

27 Feb 2009, 5:13 PM
#3
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: acces visitor's cart outside zen....

include application_top.php before you try to access zen session

I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

27 Feb 2009, 6:28 PM
#4
adrian_hs avatar

adrian_hs

New Zenner

Join Date:
Jul 2008
Posts:
14
Plugin Contributions:
0

Re: acces visitor's cart outside zen....

yellow1912:

include application_top.php before you try to access zen session

The problem is then if i wrote```
require_once('../includes/application_top.php');


then it tryes get me to "zc_install/index.php" which doesn't exists of course.

:oops:
27 Feb 2009, 6:36 PM
#5
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: acces visitor's cart outside zen....

In principle though yellow1912's suggestion is the right direction as application_top loads all that you need to access Zen Cart and restarts the session for you.

However, I have a vague memory that at although it's designed for the paths to be relative, some don't are more dependant upon being in specific locations than is ideal and that's maybe why it flips over to the installation routine instead.

I'd recommend taking a look at DrByte's Sidebox Anywhere mod to see a file structure that works.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

1 Mar 2009, 4:10 PM
#6
adrian_hs avatar

adrian_hs

New Zenner

Join Date:
Jul 2008
Posts:
14
Plugin Contributions:
0

Re: acces visitor's cart outside zen....

Thanks for suggestions! I have figure it out! Y will be back to explain it in detail - for now back to work :P

11 Mar 2009, 2:47 PM
#7
accension avatar

accension

New Zenner

Join Date:
Jan 2008
Posts:
42
Plugin Contributions:
0

Re: acces visitor's cart outside zen....

Any update on this? I need to pass this cookie to wordpress for authentication purposes (make sure user is logged in).

I tried including application_top but it breaks the wordpress.

12 Mar 2009, 7:54 AM
#8
adrian_hs avatar

adrian_hs

New Zenner

Join Date:
Jul 2008
Posts:
14
Plugin Contributions:
0

Re: acces visitor's cart outside zen....

Ok, look here is what i've done:
create a file "what-you-want.php" and put in it the following code

include_once('includes/application_top.php');

$zenId = empty($_POST['zenid']) ? trim($_GET['zenid']) : trim($_POST['zenid']);
	
	
session_start();
session_id($zenId);

//------your code below-----------//

Now upload this file to the root directory of your store - i mean /.

Because I use ajax to load this file i send the 'zenid' through POST but you can simply send it by GET calling the file from your zen-cart template like:

<img src="what-you-want.php?zenid=<?php echo session_id() ?>" alt="image" />

Or else if you want to find the zen-cart's* session_id()* through JavaScript (my speciality ;)) you'll need to get the value of the cookie called zenid. Example here: http://www.w3schools.com/JS/js_cookies.asp

But remember, this will only allow you the accest to zen-cart session, I really don't know how could that affect the other sessions created by third-parties on your site - so use it wisely.