Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Next: Allow getCart() to accept an explicit cart ID (#13775)
Damian Legawiecf8425971ba19
diff --git a/packages/next/.changeset/get-cart-explicit-id.md b/packages/next/.changeset/get-cart-explicit-id.mdnew file mode 100644index 0000000000..84d6cba61e--- /dev/null+++ b/packages/next/.changeset/get-cart-explicit-id.md@@ -0,0 +1,5 @@+---+"@spree/next": patch+---++Allow `getCart()` to accept an optional `explicitCartId` parameter. When provided, fetches that specific cart directly by ID instead of reading from cookies. Needed for the confirm-payment flow where the cart ID is known from the URL but cookies may have been cleared.diff --git a/packages/next/CHANGELOG.md b/packages/next/CHANGELOG.mdindex 47477c2860..ddbe6d0817 100644--- a/packages/next/CHANGELOG.md+++ b/packages/next/CHANGELOG.md@@ -1,5 +1,11 @@# @spree/next+## 0.10.4++### Patch Changes++- Allow `getCart()` to accept an optional `explicitCartId` parameter. When provided, fetches that specific cart directly by ID instead of reading from cookies. Needed for the confirm-payment flow where the cart ID is known from the URL but cookies may have been cleared.+## 0.10.3### Patch Changesdiff --git a/packages/next/package.json b/packages/next/package.jsonindex 224038fe70..190d2b3524 100644--- a/packages/next/package.json+++ b/packages/next/package.json@@ -1,6 +1,6 @@{"name": "@spree/next",- "version": "0.10.3",+ "version": "0.10.4","description": "Next.js integration for Spree Commerce — server actions, caching, and cookie-based auth","type": "module","main": "./dist/index.js",diff --git a/packages/next/src/actions/cart.ts b/packages/next/src/actions/cart.tsindex 6265e88d6a..ea8db6e246 100644--- a/packages/next/src/actions/cart.ts+++ b/packages/next/src/actions/cart.ts@@ -12,11 +12,12 @@ import {/*** Get the current cart. Returns null if no cart exists.+ * @param explicitCartId - Optional cart ID to fetch directly, bypassing cookie lookup.*/-export async function getCart(): Promise<Cart | null> {+export async function getCart(explicitCartId?: string): Promise<Cart | null> {const spreeToken = await getCartToken();const token = await getAccessToken();- const cartId = await getCartId();+ const cartId = explicitCartId ?? await getCartId();if (!cartId && !token) return null;@@ -38,7 +39,9 @@ export async function getCart(): Promise<Cart | null> {return null;} catch {// Cart not found (e.g., order was completed) — clear stale cookies- await clearCartCookies();+ if (!explicitCartId) {+ await clearCartCookies();+ }return null;}}