Hi @matthewbuilds @stone’s approach is the best way to set this up. As he stated the data structure could be:
Product
There is one “Product” for each Product available in the application. For example, if a store sells three different kinds of shirts (Red, Green, and Blue), then there would be a single Product Thing created for each of those Shirts.
Fields:
Name (type: text, field: no)
Price (type: number, list: no)
Image (type: image, list: no)
Cart Product
Fields:
Product (type: Product, list: no)
Quantity (type: number, list: no)
Price (The Product’s Price * Quantity) (type: number, list: no)
Each time a User wants to add a Product to their cart, a new “Cart Product” thing should be created, in order to keep track of the Product they’d like to order and the specific quantity they need. It is also helpful to store the Price for the Cart Product(s), so the value of the Cart Product’s “Price” field should always equal (The Product’s Price * Quantity that User wants to order).
Order (i.e., Shopping cart)
Fields:
Cart Products (type: Cart Products, list: yes)
Total Price (type: number, list: no)
Date placed (type: date, list: no)
Paid? (type: yes/no, list: no)
The Order type keeps track of the list of Cart Products that the User has ordered, or wants to order. For example, if a User wants to buy three of the same Green shirts, then you would first create a new Cart Product thing, with the fields to change being:
Product = Green Shirt
Quantity = The quantity value they selected from the dropdown
Price = Green Shirt’s Price * the Quantity selected.
Then, make sure to add this Cart Product Thing to the Order thing for the Current User.
If the Current User needs to change the quantity for a particular Cart Product (e.g., they want to order 10 Green shirts instead of 3 Green Shirts), you can use the Make Changes to a Thing action which updates the Cart Product Thing for the Green Shirt, and then updates the Order Thing.
The first Make Changes to a Thing action would modify the Current cell’s List Item (in this case, the Green Shirt List Item that was created) and the fields to change are:
Quantity = 10
Price = 10 * (Current cell’s Product’s Price).
Since that Cart Item is already in the Order Thing, you can update the Total Price field in the Order thing with this expression:
Total Price = This Cart’s Cart Products’ Total Price:sum
This AirDev example is setup in the same way (just with different names for the data types: Product, Ordered Product and Order). Feel free to let me know if you have any questions! https://widgets.airdev.co/bubble-widget/shopping-cart-1472621296515x898289732169359900