Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2008
    Posts
    14
    Plugin Contributions
    0

    help question 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:
    Code:
    $visitorsCart = $_SESSION['cart'];
    which is an object and if you count() you'll find the number of products in cart:
    Code:
    $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?

  2. #2
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default 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)

  3. #3
    Join Date
    Oct 2006
    Posts
    5,477
    Plugin Contributions
    11

    Default 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

  4. #4
    Join Date
    Jul 2008
    Posts
    14
    Plugin Contributions
    0

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

    Quote Originally Posted by yellow1912 View Post
    include application_top.php before you try to access zen session
    The problem is then if i wrote
    Code:
     require_once('../includes/application_top.php');
    then it tryes get me to "zc_install/index.php" which doesn't exists of course.


  5. #5
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default 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)

  6. #6
    Join Date
    Jul 2008
    Posts
    14
    Plugin Contributions
    0

    Default 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

  7. #7
    Join Date
    Jan 2008
    Posts
    42
    Plugin Contributions
    0

    Default 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.

  8. #8
    Join Date
    Jul 2008
    Posts
    14
    Plugin Contributions
    0

    Idea or Suggestion 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

    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:

    Code:
    <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.

 

 

Similar Threads

  1. Using zen cart sessions outside of zen cart
    By rasher in forum General Questions
    Replies: 0
    Last Post: 29 Jul 2009, 08:22 PM
  2. Use Zen Variables outside Zen Cart
    By renkforce in forum General Questions
    Replies: 0
    Last Post: 4 Mar 2009, 07:12 PM
  3. My idea for accessing zen cart sessions outside of zen...
    By glenelkins in forum General Questions
    Replies: 25
    Last Post: 2 Oct 2008, 10:57 PM
  4. general question: Add to cart from outside zen cart?
    By warpdesign in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 15 May 2007, 07:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg