Skip to main content

setCustomCartRepository

The setCustomCartRepository method allows you to specify a custom CartRepository, which overrides the default CartRepository behavior. The standard CartRepository interacts with Shopify's AJAX API (via /cart.js), which is unavailable in Custom Storefront implementations. Using setCustomCartRepository, you can provide custom methods to manage the cart in a way compatible with your custom storefront.

Types​

CartRepositoryInterface​

Your custom repository must implement this interface:

CartRepositoryInterface
interface

Interface for cart repository implementations. Defines methods for interacting with the cart API.

Methods
addToCart(params)Promise<{ cart: { discount_codes: { applicable: boolean; code: string }[]; items: { id: string | number; key?: string; product_id: number; quantity: number; variant_id: number }[]; token: string }; sections?: Record<string, string | null> }>
Adds items to the cart.
Parameters
NameTypeDescription
params{ items: { properties?: Record<string, string>; quantity: number; variantID: number }[]; sections?: string[] }Parameters for adding items
Returns:
Promise<{ cart: { discount_codes: { applicable: boolean; code: string }[]; items: { id: string | number; key?: string; product_id: number; quantity: number; variant_id: number }[]; token: string }; sections?: Record<string, string | null> }>
Promise with updated cart and optional sections
changeCartItem(params)Promise<{ cart: { discount_codes: { applicable: boolean; code: string }[]; items: { id: string | number; key?: string; product_id: number; quantity: number; variant_id: number }[]; token: string }; sections?: Record<string, string | null> }>
Updates the cart with discount codes, attributes, or other modifications.
Parameters
NameTypeDescription
params{ lineKey?: string; quantity: number; sections?: string[]; variantID: number }Update parameters
Returns:
Promise<{ cart: { discount_codes: { applicable: boolean; code: string }[]; items: { id: string | number; key?: string; product_id: number; quantity: number; variant_id: number }[]; token: string }; sections?: Record<string, string | null> }>
Promise with updated cart data
getCart()Promise<{ cart: { discount_codes: { applicable: boolean; code: string }[]; items: { id: string | number; key?: string; product_id: number; quantity: number; variant_id: number }[]; token: string } }>
Retrieves the current cart.
Returns:
Promise<{ cart: { discount_codes: { applicable: boolean; code: string }[]; items: { id: string | number; key?: string; product_id: number; quantity: number; variant_id: number }[]; token: string } }>
Promise with cart data
updateCart(params)Promise<{ discount_codes: { applicable: boolean; code: string }[]; items: { id: string | number; key?: string; product_id: number; quantity: number; variant_id: number }[]; sections: Record<string, string | null>; token: string }>
Parameters
NameTypeDescription
params{ attributes?: Record<string, string>; discount?: string; sections: string[] }—
Returns:
Promise<{ discount_codes: { applicable: boolean; code: string }[]; items: { id: string | number; key?: string; product_id: number; quantity: number; variant_id: number }[]; sections: Record<string, string | null>; token: string }>

CartEntity​

CartEntity
interface

Represents a shopping cart entity.

Properties
discount_codes{ applicable: boolean; code: string }[]
Applied discount codes
itemsCartItemEntity[]
Array of cart items
tokenstring
Cart token identifier

CartItemEntity​

CartItemEntity
interface

Represents a single item in the shopping cart.

Properties
idstring | number
Item ID
key?string
Ajax cart line key, unique per line even when a variant repeats
product_idnumber
Shopify product ID
quantitynumber
Item quantity
variant_idnumber
Shopify variant ID