I want to create a shopping cart in an online store. I have two ways to design shopping cart, but I don't know which one is better.
Solution 1:
create a table like below :
in this way for each product for a user add new row.
note UserId and ProductId are uniqe
Solution 2:
use two tables: shopping cart, cartItem
In this way for each user just create a record in Shoopingcart
Table .
What is your opinion?
Best Answer
Option 2 is the cannonical solution for the Order / OrderItem pattern, which a shopping cart is, in essence. It allows the cart to be treated as a whole and distinct from another cart that may be submitted by the same user an arbitrarily short time later. Fulfilment can be recorded against a cart rather than each item individually, if that is what is required.