Skip to main content
Version: 1.0.0

CartQuery

Description

Retrieves detailed information about a cart by its ID. This query allows you to fetch the current state of a cart, including items, addresses, selected shipping and payment methods, and totals.

Endpoint

query cart($cartId: String!, $siteId: Int) {
cart(cartId: $cartId, siteId: $siteId) {
# Return fields
}
}

Arguments

ArgumentTypeRequiredDescription
cartIdStringYesThe unique identifier of the cart to retrieve. This ID is obtained from createGuestCart or createCustomerCart mutations.
siteIdIntNoThe site ID where the cart is created. Defaults to 1 if not provided.

Return Values

The query returns a CartType object with the following structure:

FieldTypeDescription
billing_addressObjectThe billing address associated with the cart.
shipping_addressObjectThe shipping address associated with the cart.
items[CartItem]Array of items in the cart.
selected_shipping_methodObjectThe selected shipping method for the cart.
selected_payment_methodObjectThe selected payment method for the cart.
totalsObjectCart totals information.

CartItem Structure

Each item in the items array contains:

FieldTypeDescription
idStringUnique identifier for the cart item.
quantityIntQuantity of the product in the cart.
tax_percentFloatTax percentage applied to this item.
total_weightFloatTotal weight of this item.
nameStringProduct name.
skuStringProduct SKU.
thumbnailStringURL to the product thumbnail image.
customObjectCustom data associated with this item.
priceMoneyBase price of the product.
price_tax_amountMoneyTax amount for a single unit.
price_including_taxMoneyPrice including tax for a single unit.
price_excluding_taxMoneyPrice excluding tax for a single unit.
row_totalMoneyTotal price for this item (quantity × price).
row_total_tax_amountMoneyTotal tax amount for this item.
row_total_including_taxMoneyTotal price including tax for this item.
row_total_excluding_taxMoneyTotal price excluding tax for this item.

Money Structure

Price fields use the Money structure:

FieldTypeDescription
valueFloatThe numerical value.
currencyStringThe currency code (e.g., "USD").

Address Structure

The billing_address and shipping_address fields contain:

FieldTypeDescription
firstnameStringFirst name.
lastnameStringLast name.
companyStringCompany name.
streetStringStreet address.
cityStringCity.
regionStringRegion or state.
postcodeStringPostal or ZIP code.
country_idStringCountry code.
telephoneStringPhone number.
emailStringEmail address.

Totals Structure

The totals field contains:

FieldTypeDescription
grand_totalMoneyThe total amount for the cart including tax, shipping, and discounts.
subtotalMoneyThe subtotal amount for the cart (sum of all items before tax, shipping, and discounts).
tax_amountMoneyThe total tax amount for the cart.
shipping_amountMoneyThe shipping amount for the cart.
discount_amountMoneyThe discount amount applied to the cart.

Usage Example

query {
cart(cartId: "abc123") {
items {
id
quantity
name
sku
price {
value
currency
}
row_total {
value
currency
}
}
billing_address {
firstname
lastname
street
city
postcode
country_id
telephone
email
}
shipping_address {
firstname
lastname
street
city
postcode
country_id
telephone
}
selected_shipping_method {
carrier_code
method_code
carrier_title
method_title
amount {
value
currency
}
}
selected_payment_method {
code
title
}
totals {
grand_total {
value
currency
}
subtotal {
value
currency
}
tax_amount {
value
currency
}
shipping_amount {
value
currency
}
discount_amount {
value
currency
}
}
}
}

Example Response

{
"data": {
"cart": {
"items": [
{
"id": "123",
"quantity": 2,
"name": "Sample Product",
"sku": "product-123",
"price": {
"value": 19.99,
"currency": "USD"
},
"row_total": {
"value": 39.98,
"currency": "USD"
}
}
],
"billing_address": {
"firstname": "John",
"lastname": "Doe",
"street": "123 Main St",
"city": "Anytown",
"postcode": "12345",
"country_id": "US",
"telephone": "555-123-4567",
"email": "john.doe@example.com"
},
"shipping_address": {
"firstname": "John",
"lastname": "Doe",
"street": "123 Main St",
"city": "Anytown",
"postcode": "12345",
"country_id": "US",
"telephone": "555-123-4567"
},
"selected_shipping_method": {
"carrier_code": "flatrate",
"method_code": "flatrate",
"carrier_title": "Flat Rate",
"method_title": "Fixed",
"amount": {
"value": 5.00,
"currency": "USD"
}
},
"selected_payment_method": {
"code": "checkmo",
"title": "Check / Money Order"
},
"totals": {
"grand_total": {
"value": 44.98,
"currency": "USD"
},
"subtotal": {
"value": 39.98,
"currency": "USD"
},
"tax_amount": {
"value": 0,
"currency": "USD"
},
"shipping_amount": {
"value": 5.00,
"currency": "USD"
},
"discount_amount": {
"value": 0,
"currency": "USD"
}
}
}
}
}

Notes

  • If the cart has been converted to an order, this query will throw an error with the message "The cart has already been converted to an order. Register a new cart to continue."
  • The cart must exist for the query to succeed. If the cart ID is invalid, an error will be returned.
  • This query will return the most up-to-date information about the cart, including any changes made by other mutations.
  • The reload parameter is set to true internally, which means the cart data is always refreshed from the database before being returned.