I usually set up a session for each user store that session into a table then of course have all products in the database as well..
From there i just create a 3rd table which holds information of which products each sessionid has added to the cart.
id|sessionid|productid|quanity
Than a simply left join of the products table, session table with cart to add results up.