diff options
author | 2024-09-12 00:53:42 +0100 | |
---|---|---|
committer | 2024-09-12 00:53:42 +0100 | |
commit | 93f5312983788c615058a5c61b2535b954f1d049 (patch) | |
tree | 5dd329caee31f319595b9e8730973fefd9653899 | |
parent | Correct dependencies of useMemo and useEffect in useVisible (diff) |
Fix some cart removal logic
-rw-r--r-- | thallium-frontend/src/slices/cart.ts | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/thallium-frontend/src/slices/cart.ts b/thallium-frontend/src/slices/cart.ts index 8761955..c30677a 100644 --- a/thallium-frontend/src/slices/cart.ts +++ b/thallium-frontend/src/slices/cart.ts @@ -1,6 +1,6 @@ import { createSlice } from "@reduxjs/toolkit"; -interface CartItem { +export interface CartItem { product_template_id: number, quantity: number, variant_id: number, @@ -35,7 +35,9 @@ const cartSlice = createSlice({ if (existingItem) { existingItem.quantity -= 1; if (existingItem.quantity === 0) { - state.cart = state.cart.filter((item) => item.product_template_id !== action.payload.product_template_id && item.variant_id !== action.payload.variant_id); + let idx = state.cart.findIndex((item) => item.product_template_id === action.payload.product_template_id && item.variant_id === action.payload.variant_id); + + state.cart.splice(idx, 1); } } }, |