CodeIgniter Forums
Combining the cart class with membership - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Combining the cart class with membership (/showthread.php?tid=25763)



Combining the cart class with membership - El Forum - 12-23-2009

[eluser]Unknown[/eluser]
Hi,

I'm building a store with CI, and I've got the displaying of items and most cart functionality working fine. I want only members to be able to add items to the cart, and I can see this being relatively easy (only allow access to the controller that deals with cart functionality if the user is logged in), but what I can't see a way of doing is storing the cart data under a specific member's row in the db.

I know CI stores cart data in the sessions table, so obviously when a users log off and leaves the site (or just leaves), the cart data will be lost, but I want the data to stay if the user leaves (i.e. the cart data to be associated with a particular user). How would I go about doing this?


Combining the cart class with membership - El Forum - 12-23-2009

[eluser]Colin Williams[/eluser]
I would serialize the contents of the cart and save it in the user table.

Code:
$data['cart'] = serialize($this->cart->contents());

I've previously written cart systems that store carts in the database. I have an order table, so an unfinished order is basically a cart. But I know the CI Cart class just uses sessions. I don't really even like the fact that CI has a cart class. Best to just write your own model.