April 2020
Intermediate to advanced
716 pages
18h 55m
English
When an order is placed, we will decrease the stock quantity of each product ordered according to the quantity ordered by the user. This will automatically reflect the updated quantities of the products in the associated shops after an order is placed. We will implement this decrease product quantity update in the decreaseQuantity controller method, which will be added with the other product controller methods, as follows.
mern-marketplace/server/controllers/product.controller.js:
const decreaseQuantity = async (req, res, next) => { let bulkOps = req.body.order.products.map((item) => { return { "updateOne": { "filter": { "_id": item.product._id } , "update": { "$inc": {"quantity": -item.quantity} } } } }) ...Read now
Unlock full access