NPM Package
@commercengine/checkout
Svelte integration for Commerce Engine Checkout.
Installation
Setup
CallinitCheckout once in your root layout or entry file. The SDK resolves the hosted URL from storeId + environment using store-specific subdomains:
+layout.svelte
Feature flags, login methods, drawer direction, and payment provider are managed in Checkout Studio (Config API), not as SDK init options. Use
theme only for per-session overrides.Use the store
Import thecheckout readable store and access it with $checkout:
CartButton.svelte
Fine-grained stores
For components that only need a single value, use the individual stores to minimize re-renders:CartBadge.svelte
cartCount, cartTotal, isReady, isOpen.
Full example
App.svelte
SvelteKit
For SvelteKit, initialize in the root layout. The SDK is client-only and safely no-ops during SSR.src/routes/+layout.svelte
Store API reference
Thecheckout store value contains:
| Property | Type | Description |
|---|---|---|
isReady | boolean | true when the checkout iframe is loaded |
isOpen | boolean | true when the overlay is visible |
cartCount | number | Number of items in the cart |
cartTotal | number | Cart subtotal |
cartCurrency | string | Currency code |
isLoggedIn | boolean | Whether a user is logged in |
user | UserInfo | null | Current user info |
openCart() | function | Open the cart drawer |
openCheckout() | function | Open checkout directly |
close() | function | Close the overlay |
addToCart(productId, variantId, quantity?) | function | Add an item to the cart |
updateTokens(accessToken, refreshToken?) | function | Sync auth tokens |