Basket
This page describes all of the basket (or cart) methods available within the Limio SDK.
The Limio basket (also referred to as the cart) is a Limio object used to hold order items as a customer browses, selects offers and add-ons, and input promo codes. It enables users to build their order incrementally—adding, updating, or removing offers— as part of a pricing page, a cart page or a checkout page.
The basket is a key part of the Limio Subscription Commerce Platform and supports complex subscription logic. It is managed via the Limio SDK using hooks such as useBasket, which provides methods like initiateCheckout, addOfferToBasket, removeFromBasket, redeemPromoCode and access to the current list of items.
useBasket Hook
The useBasket hook returns an object containing basket state and methods:
const {
// State
orderItems, // Current items in the basket
basketLoading, // True when an async basket operation is in progress
formattedTotal, // Formatted total price string (e.g., "£10.00")
pageOptions, // Page configuration options
// Methods
initiateCheckout,
addOfferToBasket,
removeFromBasket,
updateItemQuantity,
swapOffer,
clearOrderItems,
navigateToCheckout,
redeemPromoCode,
removePromoCode,
updateCustomField,
setCheckoutDisabled,
validateBasket,
updateBasketDetails,
selectOfferForSubscriptionUpdate,
// Legacy (deprecated)
addToBasket, // Use initiateCheckout or addOfferToBasket instead
goToCheckout, // Use navigateToCheckout instead
} = useBasket()basketLoading - Check if basket operation is in progress
basketLoading - Check if basket operation is in progressWhen an async basket operation is running, basketLoading will be true. Use this to disable buttons and prevent double-submissions.
Note: Only one async basket operation can run at a time. Attempting to start another operation while one is in progress will throw an error.
orderItems - Retrieving items in the basket
orderItems - Retrieving items in the basketPreviously named basketItems (updated in release 109). References to basketItems should be updated where used to orderItems. The underlying data is the same.
You may want to display to users what items they have in their basket, whether this is as part of a navigation bar dropdown, or somewhere else on the page. The items can be retrieved using orderItems which are returned from the useBasket method.
Example orderItems:
initiateCheckout - Start a new checkout
initiateCheckout - Start a new checkoutUse initiateCheckout when starting a fresh basket (no existing checkoutId). This creates a new basket on the server and returns the checkout ID.
Options:
You can pass either a single order item or an order object with multiple items:
Example - Basic usage:
Example - Multiple items:
Note: This method automatically:
Creates a new basket on the server
Sends
add_to_cartanalytics eventsSets tracking tags for the offer
addOfferToBasket - Add item to existing basket
addOfferToBasket - Add item to existing basketUse addOfferToBasket when adding items to an existing basket (checkoutId already exists).
Example:
addToBasket (Legacy) - Adding items to the basket
addToBasket (Legacy) - Adding items to the basketDeprecated: Use initiateCheckout for new baskets or addOfferToBasket for existing baskets instead.
You can add an item to the basket using the addToBasket method. This method requires two parameters:
The
offerobject you want to add.An
optionsobject that may include:quantity: The number of units to add.
Example
The following example combines getOffers to display a list of available offers and addToBasket to allow a user to add an offer to their basket:
removeFromBasket - Removing items to the basket
removeFromBasket - Removing items to the basketJust as you can add an item to the basket using the addToBasket method, you can remove an item using removeFromBasket.
The removeFromBasket method requires a single parameter: an object containing the id of the item you want to remove. This id corresponds to the OrderItem that was previously added to the basket.
Example
The following example displays an item in the user's basket and allows them to remove it using the removeFromBasket method from the Limio SDK. The component receives an individual OrderItem (referred to as basketItem), retrieves the offer and product details, and renders the item label. It also includes a button to remove the item from the basket.
This is commonly used in Limio Checkout pages to display the current basket state and provide users with control over their selections.
updateCustomField - Updating custom field
updateCustomField - Updating custom fieldYou can add a custom field to the Limio order payload - and send it to third-party systems such as Zuora - by using the updateCustomField method. To do this, provide the name of the custom field and the value you want to assign. This value can be user-provided, such as from a field in the Limio Modular Checkout.
If you use Zuora as the integrated billing system, Limio will automatically set those Custom Fields on the Subscription object with Zuora. You can also specify other objects by appending .account to the custom field, as follow:
Finally, you will be able to find your custom fields in the customFields object within the order object:
setCheckoutDisabled - Disable / Enable the checkout
setCheckoutDisabled - Disable / Enable the checkoutYou can enable/disable the Limio checkout, using the setCheckoutDisabled method. This will allow for the checkout to be disabled until additional logic is carried out in an independent component, for example. The setCheckoutDisabled method requires a boolean argument to set the state of the checkout and can be called as follows:
expiresAt - Get the expiration time and date of a Basket
expiresAt - Get the expiration time and date of a BasketBaskets can expire based on how the original Session was requested. By default this is two weeks after the Session was requested. A customer can use the Basket's expiresAt attribute to understand when the Session is no longer valid and handle it on the frontend. The expiresAt attribute is returned as a UTC ISO timestamp e.g. 2023-09-20T14:50:14.679Z
redeemPromoCode - validate and add discount to basket
This function allows you to validate a promo code and apply the associated discount to the basket. A valid promo code name must be passed to the function in order to successfully validate.
removePromoCode - remove promo code from basket
This can remove an applied promo code from a basket. A customer can then either reapply that same promo code, apply a different promo code, or apply no promo code and checkout successfully.
swapOffer
swapOfferSwap an existing order item with a different offer (useful for upgrades/downgrades).
Example:
Note: This method:
Removes the old item from the basket
Adds the new offer with the same item ID
Sends both
remove_from_cartandadd_to_cartdata layer eventsAutomatically syncs the basket with the server
updateItemQuantity
updateItemQuantityUpdate the quantity of an existing order item.
Example:
clearOrderItems
clearOrderItemsRemove all items from the basket. This sends remove actions for all items to the server.
Example:
navigateToCheckout - Navigate to checkout page
navigateToCheckout - Navigate to checkout pageNavigate to the checkout page. Use this after adding items to the basket.
Options:
Example:
Note: This method requires a valid basket ID to exist. If no basket has been initiated, it will throw an error.
validateBasket - Validate basket contents
validateBasket - Validate basket contentsValidate the basket against specific rules.
Supported validation types:
"preventMixedRates"- Returnsfalseif basket contains items with mixed billing terms
Example:
updateBasketDetails - Update basket metadata
updateBasketDetails - Update basket metadataUpdate additional details on the basket (e.g., tracking information, metadata).
Note: This method runs as a parallel operation and won't block other basket operations.
selectOfferForSubscriptionUpdate - Select offer for subscription updates
selectOfferForSubscriptionUpdate - Select offer for subscription updatesFor subscription update checkouts only. Select an offer to update as part of the subscription checkout.
Note: Only one offer can be active in a subscription update checkout at a time. Selecting a new offer will reset your checkout.
Example:
goToCheckout (Legacy)
goToCheckout (Legacy)Deprecated: Use navigateToCheckout instead.
Navigate to checkout, optionally initiating or updating the basket first.
Last updated
Was this helpful?

