Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

priyalaks's avatar

Multiple Combination of Product and Its Variation

For my e-commerce website , I am trying to multiple combination of a product variant . For Example :

 Product : Shirt 
Combination of the Variant : Size  and Color
Product : Mobile Phone
Combination of the Variant : RAM , Storage Capacity , Colors
Product : Fruits
Combination of the Variant : Weight

and keeps on varying based on each product - so how could I dynamically upload the variants of these products . How should I design my database to accomodate such a requirement.

0 likes
7 replies
Lara_Love's avatar

Hello If you mean to make the product and its features dynamic. We did this and made a separate table for each feature and connected them using relationships. It was a very complicated task. Of course, we are very amateurs. I hope I was able to help

priyalaks's avatar

@LoverCode The feature itself is a dynamic one .. It would vary with product by product . That we could know only when an admin upload a product .

priyalaks's avatar

@Tray2 The Blog looks very usefull . Thanks much for sharing .. I will try to impleent the One-to-many and let you know the out come.

2 likes
priyalaks's avatar

@Tray2 I tried the One-To-Many -> But I ran into another confusion . So now the combination of each property would have different price ranges . How do we achieve that piece. For Example

Product : Mobile Phone
Combination of the Variant : RAM , Storage Capacity , Colors
RAM : 32GB
Storage Capacity : 32 GB,
Color: white
price : $ 500
RAM : 555GB
Storage Capacity : 555GB,
Color: red
price : $  5500
Tray2's avatar

@priyalaks They should each have a unique product_id.

  1. iPhone 32Gb Color White
  2. iPhone 32Gb Color Blue
  3. iPhone 64Gb Color White

and so on, each product can have one or more properties, I would however not put the price as a property, that should either be in its own table or in the products table, I would probably go with it's own table for track-ability.

It means that you have the following in your properties table

pid   property  value
1        color         white 
1        ram           32Gb
2      color          blue
2      ram            32Gb
3      color          white
3      ram.          64Gb
martinbean's avatar

@priyalaks I’ve answered this a question a few times here on Laracasts.

Basically, you want three models: a product model, an attribute model, and a SKU model. You can then create a pivot table between attributes and SKUs where you have a pivot column holding the value for an attribute and SKU combination.

Please or to participate in this conversation.