517 viewsMern Amazona

How to add color selection and size selection

Bassir Answered question August 2, 2023

it is a big feature and I have a plan to implement it like this:

in product model add this:

<code>items: [
     {
       price: Number,
       size: String,
       color: String,
       countInStock: Number,
       isDefault: Boolean,
     },
   ],
   defaultItem: {
     price: Number,
     size: String,
     color: String,
     countInStock: Number,
   },
</code>

and handle it in the product edit screen. for listing price use the default item

instead of product.price use product.defaultItem.price and etc.

Bassir Answered question August 2, 2023