mirror of
https://github.com/vercel/commerce.git
synced 2025-05-08 10:47:51 +00:00
Fix
This commit is contained in:
parent
bf6016cc10
commit
c131178529
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user