From 85b1c137b1f79046c3dad2a393b210027ecee3ae Mon Sep 17 00:00:00 2001 From: prateekgb123 Date: Mon, 14 Jul 2025 10:26:45 +0530 Subject: [PATCH] fixed the error of cart subtotal --- frontend/src/actions/cartActions.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/frontend/src/actions/cartActions.js b/frontend/src/actions/cartActions.js index bd69be4..92fd218 100644 --- a/frontend/src/actions/cartActions.js +++ b/frontend/src/actions/cartActions.js @@ -6,22 +6,25 @@ const addToCart = (productId, qty) => async (dispatch, getState) => { try { const { data } = await Axios.get("/api/products/" + productId); dispatch({ - type: CART_ADD_ITEM, payload: { + type: CART_ADD_ITEM, + payload: { product: data._id, name: data.name, image: data.image, price: data.price, countInStock: data.countInStock, - qty - } + qty, + }, }); - const { cart: { cartItems } } = getState(); + const { + cart: { cartItems }, + } = getState(); Cookie.set("cartItems", JSON.stringify(cartItems)); - } catch (error) { - + } -} +}; + const removeFromCart = (productId) => (dispatch, getState) => { dispatch({ type: CART_REMOVE_ITEM, payload: productId });