Skip to main content
shoppy.cart
Full-featured cart management with session persistence, reactive subscriptions, and Shopify checkout integration.
See Types for full interface definitions.

Features

  • Session Persistence - Cart state persists across page reloads within the browser session
  • Reactive Updates - Subscribe to cart changes for automatic UI updates
  • Full CRUD - Add, update, remove, and clear cart items
  • Shopify Checkout - Direct integration with Shopify’s hosted checkout

Methods

Quick Example

// Initialize cart on page load
await shoppy.cart.init()

// Subscribe to changes for UI updates
shoppy.cart.subscribe((cart) => {
    document.querySelector('.cart-count').textContent = cart?.totalQuantity ?? 0
})

// Add product to cart
await shoppy.cart.add('gid://shopify/ProductVariant/123', 2)

// Update quantity
const lines = shoppy.cart.lines()
await shoppy.cart.update(lines[0].id, 5)

// Proceed to checkout
shoppy.cart.checkout()