nikolayandreev's avatar

DB Design for Attributes with multiple values + Variants

Hi there, I have this design for the following flow: 1.You can add Attributes Size, Color. 2.Then you can add possible values to those attributes S,M,L, XL / Red,Green,Blue,White

In the product create/edit page you can first select the product attributes and values. So you choose attributes Size and Color and then you are presented with selects to choose from all possible values and associate them with the product.

So you end up with Sizes: S,M,L and Color: Red,Green.

That part is easy, I already done it, but now the next one is tricky..

You can make variations out of the attributes and values you just picked, so you want to make variants for the product with

Size: S Color: Red, Size M, Color: Red, Size S, Color: Green, Size M, Color: Green,

I can't wrap my head around the variations parts..

This is the DB Design I am trying to put to work:

https://i.stack.imgur.com/ODiCE.png

Any suggestions would be much appreciated

0 likes
4 replies
bugsysha's avatar

The easiest way is a double/nested foreach loop. Post here what you have so it is easier to write on top of that than to guess everything.

nikolayandreev's avatar

@robstar Hey mate, I have the suspission that this setup will be no good just by looking at the db design, it's my first goal at ecommerce flow so it was partially expected too..

So by variations I mean the combinations of attributes indeed. You can have for example Black shirt size S, M and Green shirt size M only of the same product for example. I haven't fully read the docs you've send me I will give it a read.

Robstar's avatar

I'm in no way recommending you use Opencart as it's awful software.

However, have a look at their database schema as they support attribute variations.

Please or to participate in this conversation.