mirror of
https://github.com/vercel/commerce.git
synced 2025-05-08 18:57: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 { cookies } from 'next/headers';
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
let cartId: string | undefined;
|
|
||||||
|
|
||||||
export async function addItem(prevState: any, selectedVariantId: 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) {
|
if (!cartId || !selectedVariantId) {
|
||||||
return 'Error adding item to cart';
|
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) {
|
export async function removeItem(prevState: any, merchandiseId: string) {
|
||||||
cartId = cartId || cookies().get('cartId')?.value;
|
let cartId = cookies().get('cartId')?.value;
|
||||||
|
|
||||||
if (!cartId) {
|
if (!cartId) {
|
||||||
return 'Missing cart ID';
|
return 'Missing cart ID';
|
||||||
@ -57,7 +55,7 @@ export async function updateItemQuantity(
|
|||||||
quantity: number;
|
quantity: number;
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
cartId = cartId || cookies().get('cartId')?.value;
|
let cartId = cookies().get('cartId')?.value;
|
||||||
|
|
||||||
if (!cartId) {
|
if (!cartId) {
|
||||||
return 'Missing cart ID';
|
return 'Missing cart ID';
|
||||||
@ -99,7 +97,7 @@ export async function updateItemQuantity(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function redirectToCheckout() {
|
export async function redirectToCheckout() {
|
||||||
cartId = cartId || cookies().get('cartId')?.value;
|
let cartId = cookies().get('cartId')?.value;
|
||||||
|
|
||||||
if (!cartId) {
|
if (!cartId) {
|
||||||
return 'Missing cart ID';
|
return 'Missing cart ID';
|
||||||
@ -116,6 +114,5 @@ export async function redirectToCheckout() {
|
|||||||
|
|
||||||
export async function createCartAndSetCookie() {
|
export async function createCartAndSetCookie() {
|
||||||
let cart = await createCart();
|
let cart = await createCart();
|
||||||
cartId = cart.id;
|
cookies().set('cartId', cart.id);
|
||||||
cookies().set('cartId', cartId);
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user