Adding Multiple Products to an order

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.
3 Likes