mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 23:46:58 +00:00
23 lines
663 B
TypeScript
23 lines
663 B
TypeScript
import { getCart } from 'lib/shopify';
|
|
import { cookies } from 'next/headers';
|
|
import CartModal from './modal';
|
|
|
|
export default async function Cart() {
|
|
const cartId = cookies().get('cartId')?.value;
|
|
let cart;
|
|
|
|
if (cartId) {
|
|
cart = await getCart(cartId);
|
|
//pass logged_in true to shopify checout to utilize customer api
|
|
//see: https://shopify.dev/docs/api/customer#step-stay-authenticated-on-checkout
|
|
const newCheckoutUrl = new URL(cart?.checkoutUrl || '');
|
|
newCheckoutUrl.searchParams.append('logged_in', 'true');
|
|
cart = {
|
|
...cart,
|
|
checkoutUrl: newCheckoutUrl.toString()
|
|
};
|
|
}
|
|
|
|
return <CartModal cart={cart} />;
|
|
}
|