sql - Representing ecommerce products and variations cleanly in the database -


i have ecommerce store building. using rails/activerecord, isn't necessary answer question (however, if familiar things, please feel free answer in terms of rails/ar).

one of store's requirements needs represent 2 types of products:

  1. simple products - these products have 1 option, such band's cd. has basic price, , quantity.
  2. products variation - these products have multiple options, such t-shirt has 3 sizes , 3 colors. each combination of size , color have own price , quantity.

i have done kind of thing in past, , done following:

  • have products table, has main information product (title, etc).
  • have variants table, holds price , quantity information each type of variant. products have_many variants.
  • for simple products, have 1 associated variant.

are there better ways doing this?

i worked on e-commerce product few years ago, , did way described. added 1 more layer handle multiple attributes on same product (size , color, said). tracked each attribute separately, , had "skus" table listed each attribute combination allowed each product. this:

attr_id   attr_name   1         size   2         color    sku_id    prod_id    attr_id    attr_val   1         1          1          small   1         1          2          blue   2         1          1          small   2         1          2          red   3         1          1          large   3         1          2          red   

later, added inventory tracking , other features, , tied them sku ids track each 1 separately.


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -