fix: addToCart, add comments

This commit is contained in:
Björn Meyer 2023-10-30 09:28:19 +01:00
parent 412cfb06e2
commit d5e2721ca1

View File

@ -84,17 +84,17 @@ export async function getCart() {
function updateCartCookie(cart: ExtendedCart): string | undefined { function updateCartCookie(cart: ExtendedCart): string | undefined {
const cartId = cookies().get('sw-context-token')?.value; const cartId = cookies().get('sw-context-token')?.value;
// cartId is set, but not valid anymore, update the cookie
if (!cartId && cart && cart.token) {
cookies().set('sw-context-token', cart.token);
return cart.token;
}
if (cartId && cart && cart.token && cart.token !== cartId) { if (cartId && cart && cart.token && cart.token !== cartId) {
cookies().set('sw-context-token', cart.token); cookies().set('sw-context-token', cart.token);
return 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; return cartId;
} }