Welcome Guest, Not a member yet? Register   Sign In
Saving CI session/cart data for an account?
#1

[eluser]YangHax[/eluser]
I want to accomplish is the following flow:
1) User comes to website and shops (CI session & cart utilized)
2) User proceeds to checkout
3) User forced to create account
4) User doesn't finish checkout for some reason
5) Some time later, user logs in from different computer, using the new account, and they're able to see all cart/session data from the earlier sesison.

I got 1-thru-4 figured out. I'm trying to think what's best way to go about #5. Any advice?

My best thought so far goes like this: when account is created - copy session/cart data into a normalized DB, and use that as back-end going forward. I'm hoping there's a more graceful solution though - something like storing session ID somewhere in DB with the account, and when the user logs in, we'd restore that session.

Thank you for any advice!
#2

[eluser]darrentaytay[/eluser]
There's no reason why you can't. Do something like, everytime a user adds to a cart, make/edit a record in the database which is the current cart serialized.

When the user logs in, check your database to see if he has a cart stored and chuck it back into the session.
#3

[eluser]YangHax[/eluser]
Thanks for the reply!

Is there a better way? Doing this whole "copy into DB" and "copy out of DB" is a lot of BS that I would love to avoid.
#4

[eluser]darrentaytay[/eluser]
How else would you expect to retrieve data stored about a user on one computer on a completely different computer? It will need to be stored somewhere and a database is as good a place as any.

You might think it's alot of BS but it's probably the simplest and securest way of doing it considering you store user information etc. about the user already in the database.
#5

[eluser]YangHax[/eluser]
... How?

By storing ID of session in DB, in association with the user account. Then, when user logs in in different computer, with same account, I pull back session ID from DB, and "assign" that session to the user currently logged in...

Any reason why this wouldn't work?
#6

[eluser]darrentaytay[/eluser]
Well Sessions are stored as Cookies on the computer you are on, so the users Session Cookie would not be accessible via another computer unless you stored the cookie itsself in a database or something.
#7

[eluser]YangHax[/eluser]
If you don't know how CI sessions work, please don't reply.
#8

[eluser]darrentaytay[/eluser]
Just trying to be helpful and if sessions aren't stored as cookies, I'd love to know how.
#9

[eluser]YangHax[/eluser]
CI stores session data in DB, and uses cookies to hold ID to that data.




Theme © iAndrew 2016 - Forum software by © MyBB