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

# CartService

`cartService` lets you read and change the cart.

Use it when your extension needs to inspect cart items, add an item, update quantities, or remove an item.

## Global Name

```ts theme={null}
cartService
```

## API

```ts theme={null}
interface CartService {
  getCartItemsCount(): number;
  getLineItems(): CartLineItem[];
  addLineItem(
    productID: string,
    variantMetaID: string,
    qty: number,
    attributes?: Record<string, string>
  ): Promise<boolean>;
  updateLineItem(lineItemID: string, qty: number): void;
  removeLineItem(lineItemID: string): Promise<void>;
}
```

## Methods

### getCartItemsCount

Returns the number of line items in the cart.

```ts theme={null}
const count = cartService.getCartItemsCount();
```

### getLineItems

Returns the current cart line items.

```ts theme={null}
const items = cartService.getLineItems();
```

Line items can include:

```ts theme={null}
interface CartLineItem {
  id: string;
  quantity: number;
  productID: string;
  product: Product | null;
  variantID: string;
  variant: ProductVariant | null;
  attributes: Record<string, string>;
  totalAmount: number;
  subtotalAmount: number;
  properties: Record<string, string>;
  requiresShipping: boolean;
  weight: number;
  weightUnit: string;
}
```

See [Data models](/models) for the complete product and variant shapes.

### addLineItem

Adds a product variant to the cart.

```ts theme={null}
const added = await cartService.addLineItem(
  "gid://shopify/Product/123",
  "gid://shopify/ProductVariant/456",
  1,
  { source: "expresso" }
);
```

Returns `true` when the item was added.

### updateLineItem

Updates the quantity of a line item.

```ts theme={null}
cartService.updateLineItem("line-item-id", 2);
```

### removeLineItem

Removes a line item from the cart.

```ts theme={null}
await cartService.removeLineItem("line-item-id");
```
