Jump to content


Photo

jCart + Processwire (session_start issue)


  • Please log in to reply
3 replies to this topic

#1 evan

evan

    Jr. Member

  • Members
  • PipPip
  • 42 posts
  • 10

Posted 24 June 2012 - 09:10 PM

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

#2 diogo

diogo

    Hero Member

  • Moderators
  • 2,014 posts
  • 1093

  • LocationPorto, Portugal

Posted 25 June 2012 - 04:57 AM

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');


#3 evan

evan

    Jr. Member

  • Members
  • PipPip
  • 42 posts
  • 10

Posted 25 June 2012 - 12:18 PM

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!

#4 evan

evan

    Jr. Member

  • Members
  • PipPip
  • 42 posts
  • 10

Posted 25 June 2012 - 01:10 PM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users