I am currently working on e-commerce functionality project for my skills development, and i am having a hard time setting up the cart functionality, specifically around handling product quantity and creating an optimal database structure. I have tried various methods, but still not able to get it to work correctly.
-
I don’t have a definitive database structure at the moment and need help designing one that can efficiently handle quantities for each product in a user’s cart.
-
I’m struggling to conceptualize and implement workflows for:
a. Adding a product to the cart and incrementing the quantity if the same product is already present.
b. Removing an item from the cart, and decreasing the quantity if more than one of the same product exists.
I also need guidance on how to display the user’s cart items effectively on the RG
Your help would be greatly appreciated!
I don’t have time right now so maybe someone can chime in with more detail. I can maybe make a mockup app prob much later today if needed by then
Just right off the bat your datatypes will be along these lines:
Order
Order ID (text, probably some randomly generated 10 digit string upon creation)
Order Items (Order Item, list)
User (User)
Subtotal (number)
Tax (number)
Grand Total (number)
Order Item
Description (text, copied from Product upon creation)
Order (Order)
Price (number, copied from Product upon creation)
Quantity (number)
Product (Product)
Product
Description (text)
Picture (image)
Price (number)
When they start adding to cart they would essentially be making their Order Items on-the-fly. Not sure about cart items temporarily being stored until they checkout, maybe a field called “Cart” on the User containing a list of Order Items? Then when they complete payment it assigns and Order ID and assigns those items to the Order…
When they add to cart it would search if the User’s list of Order Items contains it already then add to the quantity.
These fields are just off the top of my head, a lot more will be needed depending on your use-case and to do things like track Product Variants (if you need this), payment methods, etc.
As well as checks in place so if a products price is changed it modifies all current open orders and notifies them
Thank you for taking the time to share your thoughts. While your response outlines a potential database structure, my question was more focused on the exact workflows needed to handle quantities in a shopping cart scenario. Specifically, I’m looking for guidance on:
- Creating workflows to add a product to the cart and incrementing the quantity if the same product is already in the cart.
- Removing an item from the cart, and decreasing the quantity if more than one of the same product exists.
I’m also interested in detailed instructions on how to display the user’s cart items in a Repeating Group, given the database structure that we’ll ultimately agree on.
If you or anyone else could provide specific steps or direct me to relevant resources, I would greatly appreciate it. Thanks again for your assistance.
You’ve basically outlined the process yourself already…
but to give a brief overview, you’ll need the following workflows.
Create a new shopping cart
When a user clicks to add an item to their cart, and they don’t already have a cart
Create a new cart_item
When a user clicks to add an item to their shopping cart, and the item is not already in the cart
Update a cart_item
When a user clicks to add an item to their cart which is already in their cart, or they change the quantity (and the resulting quantity is still more than 0)
Delete a cart_item
When a user removes an item from their cart, or reduces its quantity to 0
Delete a shopping cart (optional)
When a user removes all items from their cart
I’m also interested in detailed instructions on how to display the user’s cart items in a Repeating Group, given the database structure that we’ll ultimately agree on.
Just use a RG with a content type of cart_item, and set its datasource to the relevant shopping_cart’s cart_items.
1 Like
Thanks for the pointers, really appreciate it. I’m still getting my head around Bubble and I’m having some trouble translating your guidance into actual workflows on the platform. Here’s what I’ve got so far in terms of data structure: I’ve created a ‘Cart’ data type which includes ‘Cart items’ and ‘Quantity’, and a ‘Cart items’ data type which includes ‘Product’, ‘Price’ and ‘Selected’.
However, I’m having trouble setting up the following workflows:
- Creating a new shopping cart when a user adds an item and they don’t have one yet.
- Creating a new cart_item when a user adds an item to their cart, and that item isn’t already in the cart.
- Updating a cart_item when a user adds an item that’s already in their cart, or changes the quantity.
- Deleting a cart_item when a user removes an item from their cart, or reduces its quantity to zero.
Also, I’m not quite sure how to set up a Repeating Group to display the user’s cart items with my current database structure. I’m having a bit of trouble getting the content type and data source set up right.
Any chance you could provide more specific instructions for these workflows?
You don’t need a Quantity field on the Cart datatype (what would it be the quantity of??)
You need a quantity field on the cart_item dataype.
However, I’m having trouble setting up the following workflows:
I’m not exactly sure what you mean by ‘having trouble setting up the following workflows’?
Having what kind of trouble? Trouble with what exactly?
Any chance you could provide more specific instructions for these workflows?
It’s a bit hard to give any specific advice when I don’t know what specific issues you’re having, or what your current Bubble skill level is.
If you don’t know how to create basic workflows yet, then I’d really recommend taking a big step back to learn the basics first.
The same goes for learning how to display data in repeating groups.
If you have any particular issue you’re having trouble with then I’m sure I, or someone else, can give you some specific guidance.
But if your issue is simply that you don’t yet know how to build basic workflows or work with fundamental Bubble elements like repeating groups, then you need to get to grips with the basics first - before tacking things like shopping carts.
But feel free to share any specific issue you’re having with this.
1 Like
Thank you for beeing so straight forward with me, i did as you said, I strarted with the basics And it works, IF anyone reading this is interested i can provide you With screen shot of Data base structure and workflows, Just Like this reply
2 Likes