meanshop
meanshop copied to clipboard
Quantity per Variant
Inventory support by product variant. E.g. sizes (S, M, L) and colors (black, white, blue, green)
@amejiarosario can you give me pointers on how to go about implementing this feature? What are the basic necessities to get this feature implemented?
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'] }
]
});
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!
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'
}
});