CartProvider and is read with useCart. Amounts are handled in minor units, so see Money for formatting.
cart/cart-provider
@replohq/sdk/cart/cart-provider
CartContextType
Public cart context type for LLM use. For adding products to cart, use useAddToCart. For buy now functionality, use useBuyNow.
CartContextTypeInternal
Internal cart context type with full functionality. This is for internal use only - external code should use the limited CartContextType.
CartProvider
Provider component that manages global cart state and operations. Handles both server-side cart synchronization and client-side optimistic updates.
useCart
Hook to access cart UI state and controls. For adding products to cart, use useAddToCart. For buy now functionality, use useBuyNow.
useCartInternal
cart/hooks/use-add-to-cart
@replohq/sdk/cart/hooks/use-add-to-cart
AddToCartItem
Describes a single item to add to the cart. Uses the merchandiseId (e.g. a variant GID) directly from data loader output. Product display data for optimistic UI is resolved automatically from the React Query cache for both single-product loaders (e.g. ProductLoader) and product-list loaders (e.g. CollectionProductsLoader, RebuyRecommendationsLoader). Pass merchandise explicitly to bypass the cache lookup when the variant is known but its product was not loaded via a supported loader.
useAddToCart
Hook for adding items to cart using merchandise IDs from data loader output.
This is the primary hook for adding items to cart in the data-loader architecture. It works with the resolver-backed CartGateway so the scaffold never needs direct integration credentials.
Merchandise display data (title, price, image) for optimistic cart UI is auto-resolved from the React Query cache for both single-product loaders (e.g. ProductLoader) and product-list loaders (e.g. CollectionProductsLoader, RebuyRecommendationsLoader). Just pass the merchandiseId. Pass merchandise explicitly only when the variant is known but its product was not loaded via a supported loader.
cart/hooks/use-buy-now
@replohq/sdk/cart/hooks/use-buy-now
BuyNowOutcome
What a buyNow call did. Out of stock is an expected storefront outcome (a buyer can race the last unit), so it rides the return value rather than a thrown error; variants carries each short variant with the purchasable remainder so the button can render a sold-out state.
useBuyNow
React hook that returns a buyNow function for express checkout flows. Handles creating the cart/checkout session server-side and redirecting the browser to checkout.
cart/cart-types
@replohq/sdk/cart/cart-types
CartDiscountAllocation
One discount Shopify applied to a cart line or to the whole cart. The amount is already subtracted from cost.totalAmount (and from cost.subtotalAmount for line-level discounts).
CartDiscountCode
Represents a discount code applied to a cart.
REPLO_ATTRIBUTION_PROPERTY
Replo attribution property added to cart/buy-now line items for order attribution in Shopify.
cart/buy-now-action
@replohq/sdk/cart/buy-now-action
buyNowAction
Server action that handles the full buy-now flow: 1. For Shopify: creates a cart via the canopy-api-backed gateway, returns checkoutUrl. 2. For Stripe: creates a Stripe checkout session via canopy-api, returns session URL.
Variant IDs are expected to already be Storefront GIDs (from data loader output). No internal→external ID mapping is needed.
cart/utils/cart-utils
@replohq/sdk/cart/utils/cart-utils
calculateCartTotals
Calculate cart totals including subtotal, discounts, and final total. When cart cost data is provided (from Shopify), uses the actual totalAmount and sums the provider’s discount allocations (automatic, code, and custom discounts, at both line and cart level) for the discount amount.
calculateLineItemsSubtotal
Sum the final (post selling-plan) price of every line item in the cart. This is the authoritative subtotal for cookie-based carts, which have no server-computed cost to rely on.
formatPrice
formatSellingPlanId
Validates and formats a Shopify selling plan ID to ensure it has the correct GID format.
Returns: The formatted selling plan ID with GID prefix, or null if no ID provided
recalculateCartCost
Recompute a cart’s cost from its line items. Cookie carts are their own source of truth (no server roundtrip) and apply no discounts, so subtotal equals total and there are no discount allocations. Without this the cost stays at the 0 it was created with, and every consumer that trusts it (cart total, checkout analytics) reports $0 for a priced cart.
cart/utils/cookie-cart-persistence
@replohq/sdk/cart/utils/cookie-cart-persistence
addToCartWithPersistence
Add lines to cart with configurable line merging strategy
clearCartCookie
Clear cart cookie
createCartWithPersistence
Create a new cart with persistence
LineMergeFn
Line merge function type - returns index of existing line to merge with, or -1 to add as new line
loadCartFromCookie
Load cart from cookie
removeCartLineItemsWithPersistence
Remove cart line items
saveCartToCookie
Save cart to cookie
updateCartInCookie
Update cart in cookie atomically (load-transform-save pattern)
updateCartLineItemWithPersistence
Update cart line item
cart/utils/variant-to-cart-line
@replohq/sdk/cart/utils/variant-to-cart-line
createOptimisticSellingPlanAllocation
Creates an optimistic selling plan allocation using product data. This matches the exact structure that Shopify returns so the UI doesn’t need conditional logic.
getCartLineAttribute
Gets a specific attribute value from a cart line.
Returns: The attribute value, or undefined if not found
getCartLineBundleInfo
Extracts bundle information from cart line attributes.
Returns: Object containing bundle ID, discount, and whether it’s a bundle item
getCartLinePricing
Calculates pricing information for a cart line, including discounts and selling plan adjustments.
Returns: Object containing compareAtPrice, discountPercentage, hasDiscount, sellingPlanAdjustedPrice, and finalPrice
getCartLineSpecialInfo
Extracts special item information from cart line attributes.
Returns: Object containing whether it’s a special item and any special instructions
getCartLineSubscriptionInfo
Extracts subscription (selling plan) information from a cart line.
Returns: Object containing isSubscription, frequency, discount, and sellingPlan
cart/gateways/cart-constants
@replohq/sdk/cart/gateways/cart-constants
Exports
cart/return-urls
@replohq/sdk/cart/return-urls
Exports
hooks/use-formatted-price
@replohq/sdk/hooks/use-formatted-price
useFormattedPrice
Use useFormattedPrice to format prices with proper currency and locale.