How do you structure the DB for this situation?

You have a predefined list of 10 “products” that you can choose from, to add or remove from/to your “Order”.

But its designed that all 10 “products” is always shown on the order-form as a list, regardless whether it was added to the order or not, only that the customer toggles on/off the ones chosen to be added, and those change styling - on the order-form - if toggled on.

Each added “product” on the “order”, allows customer to specify additional info, like quantity.

  1. How do you structure DB for “adding” and “removing” products to order?

  2. How do you structure DB for saving additional info per-product per-Order?

What I do, in short, is that I create a thing called Ordered product based on that information, which is product name, quantity ordered, unitary price, total price and whatever else you need. Then I tuck it into a list of Ordered products in a thing called Order.

To remove, just delete that Ordered product.
I suggest you use custom states as much as possible and only saving in the DB when the user clicks “Confirm order”.

But didt u say that you need to create a new thing called Ordered Products to save individual data, so isnt it using the database anyway?

Yeah, just a bit later and in batch. First saving in custom states if possible.

Thats actually my issue, i want things to go smooth while filling form, so im trying to avoid DB before saving order.

But its impossible to save, for example, quantity per-product, to a Custom state, (because the custom state doesn’t know which quantity is for which product) only if you create a thing in the database first

Hmm, will do some testings on this.

This topic was automatically closed after 70 days. New replies are no longer allowed.