Reputation: 30035
I am building an e-shop that will have configurable products. The configurable parts will need to have different prices and stocks from the main product. What database design would be best in this case?
I started with something like this.
Features
Features Options
Products
Products Features
The problem is that now I am stuck on how to save the configurable product features. I was thinking of saving their value as a json. But that will make saving price modification for a certain option difficult.
How would you go about this ?
Thank you.
Upvotes: 0
Views: 2348
Reputation: 18864
Two more tables will do the magic (below). Hacks like JSON or parseable text fields can and should always be avoided.
-- one product <id_product> can have multiple
-- product variants <id> with different features enabled
product_variant
id
id_product (one product - many variants)
-- features, enabled for certain <id_product_variant>
product_variant_enabled_feature
id
id_product_variant (one variant - many features)
id_product_feature
unique_constraint(id_product_variant, id_product_feature)
Upvotes: 2