Welcome Guest, Not a member yet? Register   Sign In
Modifying a session
#1

[eluser]BenRob[/eluser]
Hi all,

I need to be able to create a session for a cart and once I have created it I need to have add products to that cart while not overwriting what's already in there. It should be structured as

basket{
product{
id,
name,
desc
}
}

Can anyone advice what is the best way in CI to modify current sessions?

Thanks
#2

[eluser]Michael Wales[/eluser]
Personally, I wouldn't use a session, I would store it all in the database and store a unique ID in the session (that references that cart).

But, if you really wanted to store it all in the session, you could go this route:

Upon every page-load check for changes to the cart (which will be implemented via a form POST submission of some sort). If there are changes, retrieve the serialized array from the session, store in an unserialized array in the controller, pop on the new item to the array, serialize, and perform a destructive update on the session (overwriting was previously existed in the cart with the new data [which is old cart + new item]).
#3

[eluser]stevepaperjam[/eluser]
...I'd seriously check out wfCart, it's a free php class and it might save you reinventing the wheel.

I managed to integrate it nicely as a library within CI, I think there's a thread that mentions it somewhere.




Theme © iAndrew 2016 - Forum software by © MyBB