> For the complete documentation index, see [llms.txt](https://docs.liquidcommerce.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.liquidcommerce.cloud/elements-v2/cart.md). Agents can also search and read this documentation through its [MCP server](https://docs.liquidcommerce.cloud/~gitbook/mcp).

# Cart

The Cart component is a slide-out drawer that manages items, quantities, promo codes, and checkout.

## What you get

* Drawer UI with item list and totals
* Grouped items by retailer
* Quantity updates and removals
* Promo code support
* Cart persistence across sessions and tabs
* Checkout entry point

## Show a cart button (CDN)

```html
<script
  defer
  data-liquid-commerce-elements
  data-token="YOUR_API_KEY"
  data-env="production"
  data-cart-badge-button="header-cart"
  type="text/javascript"
  src="https://elements.reservebar-worker.workers.dev/all/elements.js"
></script>

<div id="header-cart"></div>
```

## Cart UI helpers (programmatic)

```js
window.LiquidCommerce.elements.ui.cartButton('header-cart', true);
window.LiquidCommerce.elements.ui.floatingCartButton(true);
window.LiquidCommerce.elements.ui.cartSubtotal('cart-total');
window.LiquidCommerce.elements.ui.cartItemsCount('items-count', { hideZero: true });
```

## Cart actions

```js
window.LiquidCommerce.elements.actions.cart.openCart();
window.LiquidCommerce.elements.actions.cart.closeCart();
window.LiquidCommerce.elements.actions.cart.toggleCart();

await window.LiquidCommerce.elements.actions.cart.addProduct([
  { identifier: '00619947000020', fulfillmentType: 'shipping', quantity: 1 },
  // Optional: pre-fill engraving — clamped to the product's maxLines/maxCharsPerLine,
  // dropped silently if the product/variant/fulfillment doesn't support it.
  {
    identifier: '00619947000020',
    fulfillmentType: 'shipping',
    quantity: 1,
    engravingLines: ['Happy Birthday', 'Love, Sam']
  }
], true);

await window.LiquidCommerce.elements.actions.cart.applyPromoCode('SUMMER20');
await window.LiquidCommerce.elements.actions.cart.removePromoCode();
await window.LiquidCommerce.elements.actions.cart.resetCart();

const cart = window.LiquidCommerce.elements.actions.cart.getDetails();
```

## Order minimums

If a retailer's minimum purchase amount isn't met, the cart shows a per-retailer "order minimum" alert (with the amount still needed) and disables the Checkout button until every retailer's minimum is met.

## Engraving on cart items

Engravable line items show an add/edit personalization control in the cart drawer. Selecting it opens the engraving form; saving emits `lce:actions.cart_item_engraving_updated`.

## Address behavior

If no address is set, add-to-cart automatically opens the address prompt, then retries the add.

## Cart events (examples)

```js
window.addEventListener('lce:actions.cart_item_added', (event) => {
  const { itemId, partNumber, quantity, engravingLines } = event.detail.data;
});

window.addEventListener('lce:actions.cart_updated', (event) => {
  const { current } = event.detail.data;
  const { subtotal, itemCount } = current;
});
```

***

**Next:** [Checkout](https://docs.liquidcommerce.cloud/elements-v2/checkout.md)
