From 2df48267a98b557323ba79c9be391196c0cefd07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Meyer?= Date: Mon, 24 Jul 2023 12:19:27 +0200 Subject: [PATCH] feat(poc): improve totalQuantity --- components/cart/actions.ts | 2 +- lib/shopware/transform.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) 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 || '',