diff --git a/components/cart/actions.ts b/components/cart/actions.ts index 1b6cbde48..770d6a628 100644 --- a/components/cart/actions.ts +++ b/components/cart/actions.ts @@ -7,7 +7,7 @@ import { ExtendedCart, ExtendedLineItem, messageKeys } from 'lib/shopware/api-ex import { revalidateTag } from 'next/cache'; import { cookies } from 'next/headers'; -export const fetchCart = async function (cartId?: string): Promise { +async function fetchCart(cartId?: string): Promise { try { const apiClient = getApiClient(cartId); const cart = await apiClient.invoke('readCart get /checkout/cart?name', {}); @@ -21,7 +21,7 @@ export const fetchCart = async function (cartId?: string): Promise', error); } } -}; +} export async function addItem(prevState: any, selectedVariantId: string | undefined) { const cart = await getCart(); @@ -73,7 +73,7 @@ export async function addItem(prevState: any, selectedVariantId: string | undefi } } -async function getCart() { +export async function getCart() { const cartId = cookies().get('sw-context-token')?.value; if (cartId) { diff --git a/components/cart/index.tsx b/components/cart/index.tsx index 0c732ca99..3b55b54d6 100644 --- a/components/cart/index.tsx +++ b/components/cart/index.tsx @@ -1,17 +1,11 @@ -import { fetchCart } from 'components/cart/actions'; -import { cookies } from 'next/headers'; +import { getCart } from 'components/cart/actions'; import CartModal from './modal'; import { transformCart } from 'lib/shopware/transform'; export default async function Cart() { - let resCart; - const cartId = cookies().get('sw-context-token')?.value; - - if (cartId) { - resCart = await fetchCart(cartId); - } - let cart; + const resCart = await getCart(); + if (resCart) { cart = transformCart(resCart); }