Skip to main content

createCartHandler

Creates an API that can be used to interact with the cart.

Anchor to createcarthandler(options)createCartHandler(options)

Anchor to getCartId
getCartId
() => string
required

A function that returns the cart id in the form of gid://shopify/Cart/c1-123.

Anchor to setCartId
setCartId
(cartId: string) =>
required

A function that sets the cart ID.

Anchor to storefront
storefront
required

The storefront client instance created by createStorefrontClient.

Anchor to buyerIdentity
buyerIdentity

Buyer identity. Default buyer identity is passed to cartCreate.

Anchor to cartMutateFragment
cartMutateFragment
string

The cart mutation fragment used in most mutation requests, except for setMetafields and deleteMetafield. See the example usage in the documentation.

Anchor to cartQueryFragment
cartQueryFragment
string

The cart query fragment used by cart.get(). See the example usage in the documentation.

Anchor to customMethods
customMethods
TCustomMethods

Define custom methods or override existing methods for your cart API instance. See the example usage in the documentation.

The handler returns the following default methods. Any custom or overwritten methods will also be available in the returned cart instance.

Anchor to addDeliveryAddresses
addDeliveryAddresses

Adds a delivery address to the cart.

Anchor to addGiftCardCodes
addGiftCardCodes

Adds gift card codes to the cart without replacing existing ones.

Anchor to addLines
addLines

Adds items to the cart. If the cart doesn't exist, a new one will be created.

Anchor to create
create

Creates a new cart.

Anchor to deleteMetafield
deleteMetafield

Removes a custom field (metafield) from the cart.

Retrieves the cart information.

Anchor to getCartId
getCartId
() => string

Retrieves the unique identifier of the cart. By default, it gets the ID from the request cookie.

Anchor to removeDeliveryAddresses
removeDeliveryAddresses

Removes a delivery address from the cart

Anchor to removeGiftCardCodes
removeGiftCardCodes

Removes gift card codes from the cart.

Anchor to removeLines
removeLines

Removes items from the cart.

Anchor to replaceDeliveryAddresses
replaceDeliveryAddresses

Replace all delivery addresses on the cart.

Anchor to setCartId
setCartId
(cartId: string) =>

Sets the unique identifier of the cart. By default, it sets the ID in the header cookie.

Anchor to setMetafields
setMetafields

Adds extra information (metafields) to the cart. If the cart doesn't exist, a new one will be created.

Anchor to updateAttributes
updateAttributes

Updates additional information (attributes) in the cart.

Anchor to updateBuyerIdentity
updateBuyerIdentity

Updates the buyer's information in the cart. If the cart doesn't exist, a new one will be created.

Anchor to updateDeliveryAddresses
updateDeliveryAddresses

Update cart delivery addresses.

Anchor to updateDiscountCodes
updateDiscountCodes

Updates discount codes in the cart.

Anchor to updateGiftCardCodes
updateGiftCardCodes

Updates gift card codes in the cart.

Anchor to updateLines
updateLines

Updates items in the cart.

Anchor to updateNote
updateNote

Updates the note in the cart. If the cart doesn't exist, a new one will be created.

Anchor to updateSelectedDeliveryOption
updateSelectedDeliveryOption

Updates the selected delivery options in the cart. Only available for carts associated with a customer access token.


Was this page helpful?