diff --git a/components/cart/actions.ts b/components/cart/actions.ts index 45e1b6053..d7ebe366b 100644 --- a/components/cart/actions.ts +++ b/components/cart/actions.ts @@ -41,7 +41,7 @@ export const addItem = async (variantId: string | undefined): Promise transformLineItem(lineItem)) || [], - totalQuantity: resCart.lineItems?.length || 0 + totalQuantity: resCart.lineItems ? calculateTotalCartQuantity(resCart.lineItems) : 0 }; } +function calculateTotalCartQuantity(lineItems: ExtendedLineItem[]) { + let totalQuantity = 0; + lineItems.forEach((lineItem) => { + totalQuantity += lineItem.quantity ?? 0; + }); + + return totalQuantity; +} + function transformLineItem(resLineItem: ExtendedLineItem): CartItem { return { id: resLineItem.id || '',