Variants or Combinations of products

Hi, I’m creating a simple ERP for a fashion business, I need to create under the product the combinations of colours and sizes. A bit like prestashop if you know it.

So I need to be able to select 2 colours and the sizes like S,M,L,XL,2XL,3XL and I need to generate one record for each so 2 colours x 6 sizes so 12 row in the combinations table.

I think I need a loop, and I think I need 3 variable, one for the colour, one for the size and a one for the total 12 in this case. it’s kind of a loop on a loop no ?

Someone did something like that ?

1 Like

Hey, there is a more efficient way of doing this, check this out :slight_smile:
Also here is the code I’m using for the formula with the courtesy of Claude:

colors.flatMap((color) => sizes.map((size) => ({ color, size })))

Thanks you are so quick :slight_smile: I will have a look and come back to you

1 Like