---
title: getCart
description: Returns the current cart.
source_url:
  html: 'https://shopify.dev/docs/api/storefront-events-and-actions/actions/get-cart'
  md: >-
    https://shopify.dev/docs/api/storefront-events-and-actions/actions/get-cart.md
api_name: storefront-events-and-actions
---

# get​Cart

Returns the current cart without changing it.

You can use this to read cart contents before deciding what to do, or to reconcile your own state with the current cart.

`getCart` [isn't configurable](https://shopify.dev/docs/api/storefront-events-and-actions/actions/configure), so it returns the same shape on every storefront. `cart` is `null` when the buyer doesn't have a cart yet.

If several parts of the page ask for the cart at the same time, then they share one request rather than each making their own.

## get​Cart(**[payload](#getcart-propertydetail-payload)**​,**[options](#getcart-propertydetail-options)**​)

Reads the current cart. This action isn't configurable, so it returns the same cart on every storefront.

### Parameters

* **payload**

  **GetCartPayload**

* **options**

  **GetCartOptions**

### Returns

* **Promise\<GetCartResult>**

### GetCartPayload

The payload for a \`getCart\` call.

* cartId

  The cart GID or raw cart token. If you leave it out, the action finds the cart from the browser cookie.

  ```ts
  string
  ```

### GetCartOptions

Options for a \`getCart\` call.

* signal

  Aborts the request when the signal fires.

  ```ts
  AbortSignal
  ```

### GetCartResult

The value a \`getCart\` call resolves with.

* cart

  The current cart, or \`null\` when no cart exists yet.

  ```ts
  CartSummary | null
  ```

### CartSummary

A cart, as actions report it.

* id

  The cart GID.

  ```ts
  string
  ```

* totalQuantity

  The total number of items across every line.

  ```ts
  number
  ```

* cost

  The cart cost.

  ```ts
  CartCost
  ```

* lines

  The lines in the cart.

  ```ts
  CartLine[]
  ```

* discountCodes

  The discount codes on the cart.

  ```ts
  CartDiscountCode[]
  ```

### CartCost

The cost of a cart or a cart line.

* totalAmount

  The total amount.

  ```ts
  Price
  ```

### Price

An amount with its currency.

* amount

  A decimal money amount, such as \`29.99\`.

  ```ts
  string
  ```

* currencyCode

  The three-letter currency code, such as \`USD\`.

  ```ts
  string
  ```

### CartLine

A single line in the cart.

* id

  The cart line ID.

  ```ts
  string
  ```

* quantity

  The quantity for the line.

  ```ts
  number
  ```

* cost

  The line cost.

  ```ts
  CartCost
  ```

### CartDiscountCode

A discount code on the cart.

* applicable

  Whether the cart accepted the code.

  ```ts
  boolean
  ```

* code

  The code as the buyer entered it.

  ```ts
  string
  ```

Examples

### Examples

* #### Call the action

  ##### JavaScript

  ```javascript
  const { cart } = await Shopify.actions.getCart();

  if (cart) {
    console.log(cart.totalQuantity, cart.cost.totalAmount.amount);
  }
  ```

  ##### Response

  ```json
  {
    "cart": {
      "id": "gid://shopify/Cart/c1-a1b2c3d4",
      "totalQuantity": 2,
      "cost": {
        "totalAmount": { "amount": "59.98", "currencyCode": "CAD" }
      },
      "lines": [
        {
          "id": "gid://shopify/CartLine/1",
          "quantity": 2,
          "cost": {
            "totalAmount": { "amount": "59.98", "currencyCode": "CAD" }
          }
        }
      ],
      "discountCodes": []
    }
  }
  ```

***
