I'm working on an ecommerce app that will be using a NoSQL document database. I want to have a general purpose product that can be used for different types of products, ranging from coffee to furniture to electronics.
I thought one way to achieve this is to have "attributes" and "values" so that depending on the product, there can be different ones and I can use them as "options" for the user to select on the front-end.
For example, in the case of a tshirt, attributes and their values could be:
{
"productOptions": [
{ "colors": ["red", "white", "blue"] },
{ "sizes": ["small", "medium", "large", "extra large"] }
]
}
There are 4 issues that I'm trying to solve here:
- It's fairly typical that each unique configuration will have a different SKU number
- In some cases, it's also fairly common to have a different price point for a particular SKU. For example, the regular tshirt price could be $9.99 but the extra large could be $12.99.
- Another possibility is that a particular configuration option may not be available. Using the
Product
object example above, red color may not be available in extra large size - Most ecommerce systems will also allow merchants to upload an Excel sheet for importing their data into the database as nobody would like to create even 20 products with several options manually
This means, each product option/configuration may have to be represented with its own SKU and price in the database, meaning individual entries. Something like:
{
"id": 123,
"sku": "987-rs",
"name": "Quality Brand Tshirt",
"description": "100% Cotton Small Red",
"price": 9.99
},
{
"id": 234,
"sku": "987-rxl",
"name": "Quality Brand Tshirt",
"description": "100% Cotton XL Red",
"price": 12.99
}
I also thought I could have both the attribute/value in the database as well as all available SKU's, i.e. both examples above used togehter. This would allow handling product options easily on the front-end while still allowing for individual SKUs and pricing.
Another challenge with general purpose product design is that in some cases, there's no actual product configuration until the user creates it. For example, coffee or pizza. It would make no sense to create every combination of toppings and assign SKUs ahead of time. This situation is not unique to food products. The same scenario actually applies to regular products like clothing if any customization is involved.
I'm sure many others have already tackled this scenario and wanted to see how they handled it.