From c13117852960f9ed175c7f815f9f7e2b65572f8a Mon Sep 17 00:00:00 2001 From: Lee Robinson <lrobinson2011@gmail.com> Date: Sun, 28 Jul 2024 14:35:37 -0500 Subject: [PATCH] Fix --- components/cart/actions.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/components/cart/actions.ts b/components/cart/actions.ts index ae69a4879..03b8a459a 100644 --- a/components/cart/actions.ts +++ b/components/cart/actions.ts @@ -6,10 +6,8 @@ import { revalidateTag } from 'next/cache'; import { cookies } from 'next/headers'; import { redirect } from 'next/navigation'; -let cartId: string | undefined; - export async function addItem(prevState: any, selectedVariantId: string | undefined) { - cartId = cartId || cookies().get('cartId')?.value; + let cartId = cookies().get('cartId')?.value; if (!cartId || !selectedVariantId) { return 'Error adding item to cart'; @@ -24,7 +22,7 @@ export async function addItem(prevState: any, selectedVariantId: string | undefi } export async function removeItem(prevState: any, merchandiseId: string) { - cartId = cartId || cookies().get('cartId')?.value; + let cartId = cookies().get('cartId')?.value; if (!cartId) { return 'Missing cart ID'; @@ -57,7 +55,7 @@ export async function updateItemQuantity( quantity: number; } ) { - cartId = cartId || cookies().get('cartId')?.value; + let cartId = cookies().get('cartId')?.value; if (!cartId) { return 'Missing cart ID'; @@ -99,7 +97,7 @@ export async function updateItemQuantity( } export async function redirectToCheckout() { - cartId = cartId || cookies().get('cartId')?.value; + let cartId = cookies().get('cartId')?.value; if (!cartId) { return 'Missing cart ID'; @@ -116,6 +114,5 @@ export async function redirectToCheckout() { export async function createCartAndSetCookie() { let cart = await createCart(); - cartId = cart.id; - cookies().set('cartId', cartId); + cookies().set('cartId', cart.id); }