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

# .update()

> Update cart item quantities

```javascript theme={null}
openbridge.cart.update(lineId, quantity)
openbridge.cart.update(lines)
```

Updates the quantity of one or more items in the cart.

## Parameters

### Single item

| Param      | Type     | Required | Description  |
| ---------- | -------- | -------- | ------------ |
| `lineId`   | `string` | Yes      | Cart line ID |
| `quantity` | `number` | Yes      | New quantity |

### Multiple items

| Param   | Type                                                           | Required | Description      |
| ------- | -------------------------------------------------------------- | -------- | ---------------- |
| `lines` | [`CartLineUpdateInput[]`](/api/types/cart#cartlineupdateinput) | Yes      | Array of updates |

## Returns

`Promise<`[`ShopifyCart`](/api/types/cart#shopifycart)`>`

## Examples

### Update single item

```javascript theme={null}
const lines = openbridge.cart.lines()
await openbridge.cart.update(lines[0].id, 5)
```

### Update multiple items

```javascript theme={null}
const lines = openbridge.cart.lines()

await openbridge.cart.update([
    { id: lines[0].id, quantity: 2 },
    { id: lines[1].id, quantity: 4 }
])
```

### Quantity selector

```javascript theme={null}
document
    .querySelector('.quantity-input')
    .addEventListener('change', async (e) => {
        const lineId = e.target.dataset.lineId
        const quantity = parseInt(e.target.value)

        if (quantity > 0) {
            await openbridge.cart.update(lineId, quantity)
        }
    })
```

### Increment/decrement buttons

```javascript theme={null}
async function updateQuantity(lineId, delta) {
    const line = openbridge.cart.lines().find((l) => l.id === lineId)
    const newQuantity = line.quantity + delta

    if (newQuantity > 0) {
        await openbridge.cart.update(lineId, newQuantity)
    } else {
        await openbridge.cart.remove(lineId)
    }
}
```

<Tip>
  Setting quantity to 0 will **not** remove the item. Use
  [`.remove()`](/api/cart/remove) instead.
</Tip>
