I tried, for 3 weeks, to create a simple shopping cart for an e-commerce.
First of all, I structured my database with 3 grands tables.
User
Product
Cart
Shopping cart
The goal is to create a shopping cart if this doesn’t exist and to use this shopping cart in the other case.
After that, I focused on the items, and shopping cart.
If a product already existed in the shopping cart; juste make change by adding the quantity to the item.
if the product does not existed, create new item in this shopping cart !
But it doesn t worked… Someone has something like video or tuto to help me ?
Do you have 3 data types or 4 data types? I assume the Cart is a typo and that you have only 3 data types and those are User, Product and Shopping Cart.
You will need a data type of Order Line Item so that you have fields of Product and Quantity to track how many of one product the user has selected. There should also be a data type called Order. You would want to have a field on Order Line Item related to the Order data type…this means if a user has 5 products, you create 5 Order Line Item entries and one Order entry.
Doing that, you can essentially omit the data type of Shopping Cart or instead just rename it to Order…you also want a field for Status on the Order data type so you can determine if the Order is basically a shopping cart (status might be ‘Pending’) and then you’d change status to ‘Paid’ once the user has checked out…then when the user returns and wants to add another product to their ‘shopping cart’ you can create another Order entry and the relevant Order Line Item entries.