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

# Cart

> Create and manage shopping carts via the Storefront API.

## Queries

### `cart`

Fetch a cart with all line items.

```graphql theme={null}
query Cart($uid: UUID!) {
  cart(uid: $uid) {
    uid
    lineItems {
      uid
      product {
        uid
        name
      }
      quantity
      createdAt
    }
    createdAt
    updatedAt
  }
}
```

## Mutations

### `createCart`

Create a new cart for a store.

```graphql theme={null}
mutation CreateCart($input: CreateCartInput!) {
  createCart(input: $input) {
    success
    data {
      uid
    }
  }
}
```

**Input:**

| Field      | Type   | Required | Description       |
| ---------- | ------ | -------- | ----------------- |
| `storeUid` | `UUID` | Yes      | Store/project UID |

### `addToCart`

Add a product to a cart.

```graphql theme={null}
mutation AddToCart($input: AddToCartInput!) {
  addToCart(input: $input) {
    success
    data {
      uid
      lineItems {
        uid
        product { uid name }
        quantity
      }
    }
  }
}
```

**Input:**

| Field        | Type   | Required | Description                                      |
| ------------ | ------ | -------- | ------------------------------------------------ |
| `cartUid`    | `UUID` | No       | Cart UID. If omitted, reads from session cookie. |
| `productUid` | `UUID` | Yes      | Product to add                                   |
| `quantity`   | `Int`  | No       | Defaults to 1                                    |

### `updateCartLine`

Update a line item's quantity.

```graphql theme={null}
mutation UpdateCartLine($input: UpdateCartLineInput!) {
  updateCartLine(input: $input) {
    success
    data {
      uid
      lineItems { uid quantity }
    }
  }
}
```

**Input:**

| Field         | Type   | Required | Description                       |
| ------------- | ------ | -------- | --------------------------------- |
| `cartUid`     | `UUID` | Yes      | Cart UID                          |
| `lineItemUid` | `UUID` | Yes      | Line item to update               |
| `quantity`    | `Int`  | Yes      | New quantity. Set to 0 to remove. |

### `removeCartLine`

Remove a line item from a cart.

```graphql theme={null}
mutation RemoveCartLine($input: RemoveCartLineInput!) {
  removeCartLine(input: $input) {
    success
    data {
      uid
      lineItems { uid }
    }
  }
}
```

**Input:**

| Field         | Type   | Required | Description         |
| ------------- | ------ | -------- | ------------------- |
| `cartUid`     | `UUID` | Yes      | Cart UID            |
| `lineItemUid` | `UUID` | Yes      | Line item to remove |

## Types

### Cart

| Field       | Type             | Description       |
| ----------- | ---------------- | ----------------- |
| `uid`       | `UUID`           | Cart ID           |
| `lineItems` | `[CartLineItem]` | Items in the cart |
| `createdAt` | `DateTime`       |                   |
| `updatedAt` | `DateTime`       |                   |

### CartLineItem

| Field       | Type       | Description  |
| ----------- | ---------- | ------------ |
| `uid`       | `UUID`     | Line item ID |
| `product`   | `Product`  | The product  |
| `quantity`  | `Int`      | Quantity     |
| `createdAt` | `DateTime` |              |
