> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openbridge.shop/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview

> Manage shopping cart with state persistence and reactive updates

```javascript theme={null}
openbridge.cart
```

Full-featured cart management with session persistence, reactive subscriptions, and Shopify checkout integration.

<Info>See [Types](/api/types/cart) for full interface definitions.</Info>

## 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

<CardGroup cols={2}>
  <Card title=".init()" href="/api/cart/init">
    Initialize cart session
  </Card>

  <Card title=".add()" href="/api/cart/add">
    Add items to cart
  </Card>

  <Card title=".update()" href="/api/cart/update">
    Update item quantities
  </Card>

  <Card title=".remove()" href="/api/cart/remove">
    Remove items from cart
  </Card>

  <Card title=".clear()" href="/api/cart/clear">
    Remove all items
  </Card>

  <Card title=".get()" href="/api/cart/get">
    Get full cart state
  </Card>

  <Card title=".lines()" href="/api/cart/lines">
    Get cart line items
  </Card>

  <Card title=".count()" href="/api/cart/count">
    Get total item count
  </Card>

  <Card title=".checkoutUrl()" href="/api/cart/checkout-url">
    Get checkout URL
  </Card>

  <Card title=".checkout()" href="/api/cart/checkout">
    Redirect to checkout
  </Card>

  <Card title=".subscribe()" href="/api/cart/subscribe">
    Listen for cart changes
  </Card>
</CardGroup>

## Quick Example

```javascript theme={null}
// 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()
```
