Adding Multiple Products to an order

Hi guys!

I’m building an app that allows customers to place orders for items.

Where I currently stand:
By leveraging a few existing templates I’ve hacked together the ordering process in entirety for a SINGLE product. (It works)

I am however stumped on how to get users to add MULTIPLE products to a SINGLE order, while still providing total values and updating the stock levels.

My current tables are as follows:

  • User
  • Category
  • Products
  • Orders

Additional details:

Customer:
A user can: add multiple products to an order
A user can: add multiple quantities of each product to an order
A user can: place an order, see their basket and total price (standard checkout)

Admin/Shop owner:
A user can: see submitted orders and all the relevant details

Do I need to create a cart table? I would love some insights here please on how to get this working or if there are some existing examples.

Thanks!

I used to create a Cart/Order Line table for use cases like this. You tie the order ID with the multiple order lines.

1 Like

Thanks for this.

How does this work in practice? I’m a bit of a noob here.

You will also want to map out how to clone an order and it’s associated products.

The flow would look like this, assuming your users are signed in:

  • Add a Cart table that would contain the order id, the item id and the quantity.
  • In your users table, add a “current order ID” column.
  • Assuming you have an Items screen, on the entry to the details view of that screen, check if your “current order ID” is empty. If empty, set a unique ID to the “current order ID” column, then show them the details screen. Else just show them the details screen without doing anything.
  • Add a form inside each item’s details screen, allow users to set a quantity and write to the Cart table: the “current order ID”, the “item ID” and the quantity.
  • Add a Cart screen that uses a relation of “current order ID” to show items that have been added to the cart. You can leverage that relation to calculate the total cost of the order.
  • Add a submit order button that writes a row to the Orders table that contains the “current order ID”, and set a new unique ID to the Users table preparing for the next iteration.
2 Likes

(post deleted by author)

(post deleted by author)

Thanks @ThinhDinh, it took me a while to figure out because I overcomplicated my DB but your explanation makes complete sense and worked out in the end (I had to create a new file to run through your process without my overly complex DB)

Cheers!

2 Likes

Great to hear! Let me know if you need anything more about this.