Jump to content

jCart + Processwire (session_start issue)


evan
 Share

Recommended Posts

Hi folks,

Anyone have any luck getting jCart and PW to play nicely together? I can't for the life of me figure it out.

I know that it's a session_start issue, as everything works fine if I bootstrap PW after including jCart, in a normal PHP page. How can achieve the same effect within a template?

I've tried including jCart in index.php, config.php, and Process.php, but jCart still can't seem to retain its session data.

Thanks for your help!

-evan

Link to comment
Share on other sites

From what I understand, you just have to put the jcart folder on your PW templates folder, and include it on your templates with:

include_once('jcart/jcart.php');
Link to comment
Share on other sites

OK, I made a little headway. jCart appears to work fine if I comment out @session_start() in the __construct() of the Session class, and let jCart declare it. However this breaks the PW login, as it reports that the login is forged.

The problem seems to be where session_start() is declared, and when the jCart object is defined. Because the object declaration for jCart is happening after session_start(), jCart can't create the object and store it in $_SESSION.

So my new question is, where is a good place to define an object before PW starts the session, and that's accessible to templates?

Thanks for bearing with me, folks!

Link to comment
Share on other sites

All right, looks like it was my mistake. Including the jCart PHP into config.php does work, if you move the initialization code to the head of your template, which is this bit:

// Initialize jcart after session start
$jcart = $_SESSION['jcart'];
if(!is_object($jcart)) {
$jcart = $_SESSION['jcart'] = new Jcart();
}

...and also remove jCart's session_start.

Sometimes you just gotta take a break!

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...