customerCart query

The customerCart query returns the active cart for the logged-in customer. If the cart does not exist, the query creates one. The customer’s authorization token must be specified in the headers.

The customerCart query differs from the cart query in the following ways:

  • The customerCart query must be run on behalf of a logged-in customer. If you run this query on behalf of a guest, an exception will be thrown.
  • The cart query requires a cart_id value as input. The customerCart query does not take any input parameters.

You can define the query to return the id attribute. You can use the value of this attribute as the destination_cart_id input parameter in the mergeCarts mutation. (The mergeCarts mutation provides the ability to merge a guest cart with the logged-in customer’s cart.)

If you know the value of the logged-in customer’s cart ID, you can allow the customer to start an order on one device and complete it on another.

Syntax

customerCart: Cart!

Example usage

The following query lists the products in the logged-in customer’s cart:

Request:

1
2
3
4
5
6
7
8
9
10
11
12
13
{
  customerCart {
    id
    items {
      id
      product {
        name
        sku
      }
      quantity
    }
  }
}

Response:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
  "data": {
    "customerCart": {
      "id": "CYmiiQRjPVc2gJUc5r7IsBmwegVIFO43",
      "items": [
        {
          "id": "11",
          "product": {
            "name": "Strive Shoulder Pack",
            "sku": "24-MB04"
          },
          "quantity": 1
        },
        {
          "id": "12",
          "product": {
            "name": "Radiant Tee",
            "sku": "WS12"
          },
          "quantity": 1
        }
      ]
    }
  }
}

Output attributes

The customerCart query returns the Cart object.

Cart object

Attribute Data Type Description
applied_coupon AppliedCoupon Deprecated. Use applied_coupons instead
applied_coupons [AppliedCoupon] An array of AppliedCoupon objects. Each object contains the code text attribute, which specifies the coupon code
applied_gift_cards [AppliedGiftCard] An array of AppliedGiftCard objects. An AppliedGiftCard object contains the code text attribute, which specifies the gift card code. applied_gift_cards is a Commerce-only attribute, defined in the GiftCardAccountGraphQl module
applied_store_credit AppliedStoreCredit Contains store credit information applied to the cart. applied_store_credit is a Commerce-only attribute, defined in the CustomerBalanceGraphQl module
available_payment_methods [AvailablePaymentMethod] Available payment methods
billing_address BillingCartAddress Contains the billing address specified in the customer’s cart
email String The customer’s email address
id ID! The ID of the cart
is_virtual Boolean Indicates whether the cart contains only virtual products
items [CartItemInterface] Contains the items in the customer’s cart
prices CartPrices Contains subtotals and totals
selected_payment_method SelectedPaymentMethod Selected payment method
shipping_addresses [ShippingCartAddress]! Contains one or more shipping addresses

Cart query output provides more information about the Cart object.