mirror of
https://github.com/vercel/commerce.git
synced 2025-05-14 13:47:49 +00:00
fix: addToCart, add comments
This commit is contained in:
parent
412cfb06e2
commit
d5e2721ca1
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user