From d5e2721ca1a3e477335e7c3035486e47a493530c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Meyer?= Date: Mon, 30 Oct 2023 09:28:19 +0100 Subject: [PATCH] fix: addToCart, add comments --- components/cart/actions.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/cart/actions.ts b/components/cart/actions.ts index 21d4e9ddf..ea0e9969a 100644 --- a/components/cart/actions.ts +++ b/components/cart/actions.ts @@ -84,17 +84,17 @@ export async function getCart() { function updateCartCookie(cart: ExtendedCart): string | undefined { const cartId = cookies().get('sw-context-token')?.value; - - if (!cartId && cart && cart.token) { - cookies().set('sw-context-token', cart.token); - return cart.token; - } - + // cartId is set, but not valid anymore, update the cookie if (cartId && cart && cart.token && cart.token !== cartId) { cookies().set('sw-context-token', cart.token); return cart.token; } - + // cartId is not set (undefined), case for new cart, set the cookie + if (!cartId && cart && cart.token) { + cookies().set('sw-context-token', cart.token); + return cart.token; + } + // cartId is set and the same like cart.token, return it return cartId; }