Engine: Cart
The cart: CartProvider and useCart, guest and customer carts, merging on sign-in, and the cart state checkout and the mini-cart read.
Generated from packages/engine/src/cart/: 1 files, 8 exported symbols. Signatures and types are shown as written in the source.
@magenxcommerce/engine/cart/cart-context
packages/engine/src/cart/cart-context.tsxclient
CART_ID_KEY const
const CART_ID_KEY = "magenx_cart_id"PENDING_ORDER_NUMBER_KEY const
const PENDING_ORDER_NUMBER_KEY = "magenx_pending_order_number"Stores the pending order number across an off-site payment redirect (Stripe 3DS / PayPal).
PENDING_ORDER_EMAIL_KEY const
const PENDING_ORDER_EMAIL_KEY = "magenx_pending_order_email"Stores the guest email so the success page can load order details via guestOrder(email, number, lastname).
PENDING_ORDER_LASTNAME_KEY const
const PENDING_ORDER_LASTNAME_KEY = "magenx_pending_order_lastname"Stores the guest billing lastname, which guestOrder() requires alongside the email.
PLACED_ORDER_NUMBER_KEY const
const PLACED_ORDER_NUMBER_KEY = "magenx_placed_order_number"The order number this browser actually placed. Unlike PENDING_ORDER_NUMBER_KEY — which every payment path clears the moment it redirects — this survives the hop to /order/success, where it is the only proof that the visitor placed the order named in the URL. Without it the success page confirmed any ?number= a stranger typed.
CartContextValue interface
| Member | Type | Description |
|---|---|---|
cartId | string | null | |
cartQty | number | |
cartItems | CartItem[] | |
cartGrandTotal | MoneyType | null | |
cartPrices | Cart["prices"] | null | |
appliedCoupons | Array<{ code: string }> | |
garanNoticeRequired | boolean | Whether the EU legal guarantee notice belongs next to this cart (Magenx_GaranGraphQl Cart.garan_notice_required): at least one line is a good. false while loading, for an empty cart, or when the notice is off. |
isLoading | boolean | |
isAuthenticated | boolean | Whether a customer session exists. |
addToCart | (input: CartItemInput) => Promise<{ errors: string[] }> | |
removeFromCart | (cartItemUid: string) => Promise<void> | |
updateCartItemQuantity | ( cartItemUid: string, quantity: number, ) => Promise<{ error?: string }> | Updates a cart line's quantity. Resolves to { error } when Magento rejects it (e.g. "The requested qty is not available" — updateCartItems throws rather than returning user_errors), or {} on success, so callers can surface the limited-quantity message instead of failing silently. |
setCartItemGiftMessage | ( cartItemUid: string, giftMessage: GiftMessageInput | null, ) => Promise<{ error?: string }> | Sets (or clears) the gift message on a cart line item. Pass null to remove an existing message. Resolves to an error string when the mutation fails, or {} on success. |
clearCart | () => void | |
adoptCart | (id: string) => boolean | Points this browser at an existing Magento cart. Exists for ONE caller: the UCP agentic-checkout handoff, where an AI agent has built a cart server-side and sends the buyer to continue_url to pay (/[locale]/checkout?ucp=<id>). Returns true when the id was adopted. Do NOT generalize this into "read the cart id from the URL". A cart id is a bearer credential for that cart, so any surface that adopts one from an untrusted URL lets a third party decide what a shopper is about to buy. The checkout page is the only safe place for it: the shopper sees the full line items, totals and destination there, and must actively pay. |
clearCustomerAuth | () => void | |
refetchCart | () => void | |
signIn | (token: string) => Promise<void> | Completes a customer sign-in: stores the token cookie and merges the guest cart. |
completeExternalSignIn | () => Promise<void> | Completes an externally-brokered sign-in (e.g. social login) where the httpOnly token cookie has ALREADY been set server-side. Flips the local auth flag and merges the guest cart, but does not POST a token. |
applyCoupon | (code: string) => Promise<{ error?: string }> | |
removeCoupon | (code: string) => Promise<void> |
CartProvider function
CartProvider({ children }: { children: ReactNode })useCart function
useCart(): CartContextValue