mirror of
https://github.com/vercel/commerce.git
synced 2025-05-15 14:06:59 +00:00
38 lines
768 B
TypeScript
38 lines
768 B
TypeScript
import { fetchCart } from 'components/cart/actions';
|
|
import { cookies } from 'next/headers';
|
|
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 newToken;
|
|
if (!cartId && !resCart) {
|
|
resCart = await fetchCart();
|
|
if (resCart?.token) {
|
|
newToken = resCart?.token;
|
|
}
|
|
}
|
|
|
|
let cart;
|
|
if (resCart) {
|
|
cart = transformCart(resCart);
|
|
}
|
|
|
|
if (!cart) {
|
|
return null;
|
|
}
|
|
|
|
let cartIdUpdated = false;
|
|
if (cartId !== newToken) {
|
|
cartIdUpdated = true;
|
|
}
|
|
|
|
return <CartModal cart={cart} cartIdUpdated={cartIdUpdated} />;
|
|
}
|