diff --git a/src/controllers/cart.js b/src/controllers/cart.js index a6acb95..951402b 100644 --- a/src/controllers/cart.js +++ b/src/controllers/cart.js @@ -79,9 +79,9 @@ export const addNewCart = ({ userId, products = [] }) => { let totalQuantity = 0; // get products in the relevant schema - const someProducts = productsByIds.map((p, idx) => { - // get quantity of the product - const quantity = productQty[idx]; + const someProducts = productsByIds.map((p) => { + const originalIndex = productIds.indexOf(p.id); // match by id + const quantity = productQty[originalIndex]; // total price (price * quantity) const priceWithQty = p.price * quantity; @@ -219,4 +219,4 @@ export const deleteCartById = ({ id }) => { cart.deletedOn = new Date().toISOString(); return cart; -}; +}; \ No newline at end of file