Cscart_Sessions Vs Cscart_Stored_Sessions

Hi there,

I am implemented some custom remarketing logic and I am storing some information in the session. I am trying to wrap my head around the two different tables in the database:

cscart_sessions AND cscart_stored_sessions.

I gather the latter is used to store one from the first table?



The 'write' method related to the "session handler" stores session data in the DB (rather than the default filesystem). Hence the cscart_stored_sessions table is simply the saved state of the user's session. When a page is loaded, that data is present in the $_SESSION variable. Suggest you NOT try to manipulate the DB copy of the $_SESSION.

Can you describe your problem from a "symptom" perspective? I.e. I did X and expected Y but got Z?

You can certainly test things by doing a $_SESSION['my_var'] = "yes" and then reading it in a separate page via print("My_var=".$_SESSION['my_var']);


What I am trying to do is capture the users email to better track abandoned carts. I have created the HTML form where they can enter their email address (which they may submit before or after adding an item to the cart). Everything was working on my localhost and I added a variable to $_SESSION and it was saved in the database, all was working.

I then moved my code over to staging and tested it, only to find the variable I wrote to $_SESSION['cart']['user_data']['email'] was not being stored in the session data. Took my a while to figure out the difference between my local and staging environments and then remembered I had Redis enabled for sessions on 'staging' (I am now installing Redis on localhost for more accurate development).

I would have thought that adding a variable to the $_SESSION would have been written to the storage (redis, database or file) no matter what. BTW, I am guessing that at the end of the request, the session data is re-written to the storage provider? I haven't checked the code yet to clarify if this is the case - but imagine another way it would work.

One quirk I found was that I was also writing another variable to $_SESSION['captureComplete'] when the user had completed the form. This $_SESSION variable is set in the same controller as the attempt at saving the users email, this one is saved in the Redis storage, so I can't figure out why the $_SESSION['cart']['user_data']['email'] is not being saved.

Just to be clear: I am not writing directly to the database - I probably just explained it poorly!

I think you'll find that the checkout process will overwrite your $cart['user_data'] area when it's initialized. The products in the cart are stored separately in cscart_user_session_products and is then copied into the $_SESSION['cart'] when the 'checkout' controller is used.

While this will pretty much match the $_SESSION['cart'] data, the 'products' in the cart could be adjusted. I've also seen instances where users_session_products is not consistent with what was added to the cart.

Wouldn't it just be easier to have the customer login (or register) to add an item to their cart? Then all the normal system processes would just do what you want? With the "quick registration", it's nearly the same thing you are doing but is well integrated into the system processes. You should probably consider $_SESSION['cart'] to be volatile since it's affected by many other actions within cs-cart.

I didn't realize from your OP that you were storing your data in the user_data element of the session 'cart'.

Ok, thanks.

I am trying to reduce the number of obstacles for the user while also being able to get their details for remarketing. Their email is then sent to our CRM for remarketing campaigns. And its also a chance where we get to ask them a couple of questions using checkboxes which convert to CRM tags.

With registration, I need to get them to fill out their profile fields.

This way, they can just enter their email address. My comment regarding abandoned carts was also probably misleading as I didn't mention I was dealing with the CRM.

Its interesting though, that 'cart' doesn't get overwritten when not using Redis - but I won't waste any more time on that for now.

The other reason that I was using $_SESSION['cart'] to store the email is that I could use it on the abandoned carts list in the backend and display the email against the cart in case the sales team wants to get in touch with the customer. But this is not a big deal now as I will just handle all this via the CRM.