Skip to main content
openbridge.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

.init()

Initialize cart session

.add()

Add items to cart

.update()

Update item quantities

.remove()

Remove items from cart

.clear()

Remove all items

.get()

Get full cart state

.lines()

Get cart line items

.count()

Get total item count

.checkoutUrl()

Get checkout URL

.checkout()

Redirect to checkout

.subscribe()

Listen for cart changes

Quick Example

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

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

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

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

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