Skip to main content
Initializes the cart by loading an existing cart from session storage or creating a new one.
You must call init() before using any other cart methods.

Parameters

None

Returns

Promise<ShopifyCart>

Examples

Basic initialization

Initialize on page load

With subscription

Behavior

  1. Checks sessionStorage for an existing cart ID
  2. If found, fetches the cart from Shopify
  3. If not found (or cart expired), creates a new cart
  4. Stores the cart ID in sessionStorage
  5. Notifies all subscribers with the cart state