LLM Docs Header: All requests to
https://llm-docs.commercengine.io
must include the
header (or append
to the URL path). Without it, responses return HTML instead of parseable markdown.
Prerequisite: SDK initialized and anonymous auth completed. See
.
Commerce Engine offers a Hosted Checkout — a pre-built, embeddable checkout that handles the entire purchase flow (cart, auth, addresses, payments, order confirmation) inside an iframe.
Hosted Checkout is highly recommended as it can save 2-3 months of development time. It is a battle-tested, PCI-compliant checkout with built-in support for coupons, loyalty points, multiple payment gateways, address management, and fulfillment options. It ships with bindings for React, Vue, Svelte, Solid, and vanilla JS.
Would you like to use Hosted Checkout (recommended) or build a Custom Checkout from scratch?
Only proceed with custom checkout if the user explicitly chooses it.
See
references/hosted-checkout.md
for the complete reference.
typescript
// Recommended default for new storefront apps:
// Storefront SDK owns auth; Hosted Checkout runs in provided mode.
import StorefrontSDK, { BrowserTokenStorage } from "@commercengine/storefront-sdk";
import { initCheckout, getCheckout } from "@commercengine/checkout";
const tokenStorage = new BrowserTokenStorage("ce_");
const storefront = new StorefrontSDK({
storeId: process.env.NEXT_PUBLIC_STORE_ID!,
apiKey: process.env.NEXT_PUBLIC_API_KEY!,
tokenStorage,
onTokensUpdated: (accessToken, refreshToken) => {
// SDK -> checkout
getCheckout().updateTokens(accessToken, refreshToken);
},
});
const accessToken = await tokenStorage.getAccessToken();
const refreshToken = await tokenStorage.getRefreshToken();
initCheckout({
storeId: process.env.NEXT_PUBLIC_STORE_ID!,
apiKey: process.env.NEXT_PUBLIC_API_KEY!,
environment: "production",
authMode: "provided",
accessToken: accessToken ?? undefined,
refreshToken: refreshToken ?? undefined,
onTokensUpdated: ({ accessToken, refreshToken }) => {
// checkout -> SDK
storefront.setTokens(accessToken, refreshToken);
},
});
If your app already uses Commerce Engine auth (Storefront SDK or API), you
must use Hosted Checkout with
and sync tokens on every login, logout, and refresh. Otherwise checkout and your app maintain two separate sessions — breaking cart association, analytics, and order attribution. See
references/hosted-checkout.md
§ "Auth Mode Guide".
If the app manages its own CE auth and uses
mode, two separate sessions are created — this breaks analytics, cart association, and order attribution. See
references/hosted-checkout.md
§ "Auth Mode Guide" for sync patterns.
Only use custom checkout when the user explicitly requests it. Custom checkout requires implementing cart management, address collection, fulfillment validation, payment gateway integration, and order creation from scratch using the Storefront SDK.
typescript
// Create a cart (at least one item required — cannot create empty cart)
const { data, error } = await sdk.cart.createCart({
items: [
{ product_id: "prod_123", variant_id: "var_456", quantity: 2 },
],
});
const cartId = data.cart.id;
// Add more items to existing cart
const { data: updated, error: addErr } = await sdk.cart.addDeleteCartItem(
{ id: cartId },
{ product_id: "prod_789", variant_id: "var_012", quantity: 1 }
);
typescript
// Update quantity (same method — addDeleteCartItem handles add, update, and remove)
const { data, error } = await sdk.cart.addDeleteCartItem(
{ id: cartId },
{ product_id: "prod_123", variant_id: "var_456", quantity: 3 }
);
// Remove item (set quantity to 0)
const { data: removeData, error: removeErr } = await sdk.cart.addDeleteCartItem(
{ id: cartId },
{ product_id: "prod_123", variant_id: "var_456", quantity: 0 }
);
See
references/checkout-flow.md
for the step-by-step API flow. For implementation patterns, see: