skip to Main Content

I’m designing the database for a food delivery app. There are special kind of products:

Product examples:

  • Kebab (price is fixed)
  • Pizza Margherita – (price is dynamic)
  • Pizza Half-Half – (price is dynamic – there are two products combined into one)

Selections within product:

  • Each product can have selections like sizes and sauces.
  • Size selection changes the product price.
  • Sauces selection depends on size selection. For small size you have 1 sauce, for medium 2 sauces and so on. You can chose extra sauces paying extra.

What are your thoughts about this? Perhaps there is something open-source addressing this. I need to keep the Laravel style for functionalities like validations, model creations and so on.

2

Answers


  1. Chosen as BEST ANSWER

    Well, after some sketching I came up with this idea. In the first post I didn't mention the need of the scalability(in the future, more products will be available in the shop)

    So..

    Products and selections - concepts

    1. Product
    • Could have #Selection1
    • Could have #Selection2
    1. Combo product
    • Selection of two or more products
    • Could have #Selection1
    • Could have #Selection2

    The #Selection2 could be listed more times

    Selections details

    1. Selection#1
    • This is a selection that defines the product price(e.g. product sizes)
    1. Selection #2
    • This selection could be dependent by #Selection#1(if exists). It has a min. and a max. number of items, even a extra which will add to the final price.

    What's your thoughts about this and how will the database structure look like?


  2. So what you need is the database structure. What I do in this cases is write my ideas in a piece of paper, until they get better and better. It helps.

    Something quick I can recommend, you can obviously change it a bit.

    • Products table: id, name, description(nullable)
    • Product sizes table: id, size
    • Product sizes pivot table: product_id, size_id
    • Product prices table: id, product_id, size_id, price
    • Sauces table: id, sauce_name, sauce_price
    • Product sauces pivot table: product_id, sauce_id

    If someone orders a Pizza Margherita, you just calculate it’s price directly based on it’s size from the prices table.

    If someone lets say orders Half Pizza Margherita and half Pepperoni with 3 extra sauces you can do this:
    (Margherita price / 2) + (Pepperoni price / 2) + (extra sauce price + extra sauce price + extra sauce price) = total price.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search