mirror of
https://github.com/vercel/commerce.git
synced 2025-07-25 11:11:24 +00:00
.github
.vscode
app
components
cart
actions.ts
add-to-cart.tsx
delete-item-button.tsx
edit-item-quantity-button.tsx
index.tsx
modal.tsx
grid
icons
layout
product
carousel.tsx
loading-dots.tsx
logo-square.tsx
opengraph-image.tsx
price.tsx
prose.tsx
e2e
fonts
lib
.env.example
.eslintrc.js
.gitignore
.nvmrc
.prettierignore
README.md
license.md
next.config.js
package.json
playwright.config.ts
pnpm-lock.yaml
postcss.config.js
prettier.config.js
tailwind.config.js
tsconfig.json
24 lines
639 B
TypeScript
24 lines
639 B
TypeScript
import { createCart, 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 cartIdUpdated = false;
|
|
let cart;
|
|
|
|
if (cartId) {
|
|
cart = await getCart(cartId);
|
|
}
|
|
|
|
// If the `cartId` from the cookie is not set or the cart is empty
|
|
// (old carts becomes `null` when you checkout), then get a new `cartId`
|
|
// and re-fetch the cart.
|
|
if (!cartId || !cart) {
|
|
cart = await createCart();
|
|
cartIdUpdated = true;
|
|
}
|
|
|
|
return <CartModal cart={cart} cartIdUpdated={cartIdUpdated} />;
|
|
}
|