Welcome Guest, Not a member yet? Register   Sign In
Combining the cart class with membership
#1

[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?
#2

[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.




Theme © iAndrew 2016 - Forum software by © MyBB