I'm trying to build a stock management app which allows a user to create products, upload images and track Orders between sales channels such as Etsy and Shopify. I'm currently designing the database to hold the products but struggling on how to handle product variations. Products can have a few different variation types (such as colour, size etc) and within the types can have multiple variation (such as Red Size 1, Red Size 2, blue Size 1 etc) The price and quantity should be stored with the variants if a prodict has them.
I initially had 1 table however this would be very inefficient as it would be duplicating all the non variant details such as the description and images. I then switched to 2 tables, one to hold the product and the other to hold the variations, as per below.
Products
- ID (PK)
- Name
- Description
- Category
- etc...
Variations
- VariantID (PK)
- ProductID (FK - Products (ID))
- Variant Type
- Variant Name
- Quantity
- Price
I'm struggling with how to handle how some products with have variants but others wont. The products that dont have variants wouldn't have a quantity or price associated with them.
I also not sure how I would store orders for products that dont have a variant using the 2 table design above as I would need the variantID in the order table.
Orders
- OrderID (PK)
- VariantID (FK - Variants(VariantID))
- Quantity
- OrderValue
Any suggestions on how best to handle product variants?
Thanks