meanshop icon indicating copy to clipboard operation
meanshop copied to clipboard

Quantity per Variant

Open amejiarosario opened this issue 8 years ago • 4 comments

Inventory support by product variant. E.g. sizes (S, M, L) and colors (black, white, blue, green)

amejiarosario avatar Dec 22 '15 02:12 amejiarosario

@amejiarosario can you give me pointers on how to go about implementing this feature? What are the basic necessities to get this feature implemented?

prasadh13 avatar Aug 23 '16 01:08 prasadh13

sure, you can add a new field in the products model called variants. This will contain an array of values that you can initialize when you create the object.

For instance:

Product.create({
  title: 'T-shirt',
  imageUrl: '/assets/uploads/meantshirt.jpg',
  price: 15,
  stock: 100,
  description: 'T-shirt with the MEAN stack logo',
  variants: [
    { size: ['S', 'M', 'L'] },
    { color: ['navy', 'black', 'white', 'green'] }
  ]
});

amejiarosario avatar Aug 23 '16 17:08 amejiarosario

Yes. I figured that out! I am using the MEANJs boilerplate to implement this project. This is a very cool project to start building an e-commerce platform.

How will you ensure that the requested product quantity is available in the store before placing the order? Because if I am not wrong, if there are multiple requests for a product, they will have to be stored in some sort of pipeline(i have no idea how to do that) and by the time a request is rendered, if the product quantity is less, gracefully throw an error. I am looking for a solution to how to achieve this. Is there a way to do this in the current scheme?

TIA!

prasadh13 avatar Aug 23 '16 18:08 prasadh13

To keep inventory you need a unique product identifier (That's what Amazon use).

Each product will have only its variants. This way you can set the stock and price independently. Images also could be different or the same.

e.g. Let's say that the product unique identifier is 200202190 and has the variants Small and Navy or Large and Red. You can represent it as:

Product.create({
  title: 'T-shirt',
  puid: '200202190',
  imageUrl: '/assets/uploads/meantshirt-navy.jpg',
  price: 15,
  stock: 20,
  description: 'T-shirt with the MEAN stack logo',
  variants: {
    size: 'S',
    color: 'navy'
  }
});

Product.create({
  title: 'T-shirt',
  puid: '200202190',
  imageUrl: '/assets/uploads/meantshirt-red.jpg',
  price: 16,
  stock: 280,
  description: 'T-shirt with the MEAN stack logo',
  variants: {
    size: 'L',
    color: 'red'
  }
});

amejiarosario avatar Aug 23 '16 19:08 amejiarosario