Cart
Represents a cart in the store, exposing totals, items, discounts, shipping, and payment information for GraphQL APIs.
Type Definition
type Cart {
id: String
createdAt: String
customer: Customer
discounts: [CartDiscount]
tags: [String]
subtotalPrice: Float
totalPrice: Float
currency: String
totalNetPrice: Float
totalTax: Float
taxLines: [CartTaxLine]
customerNote: String
paymentMethods: [CartPaymentMethod]
paymentFee: Float
shippingMethods: [CartShippingMethod]
shippingPrice: Float
lines: [CartLineItem]
physicalLines: [CartLineItem]
lineCount: Int
shippingAddress: Address
billingAddress: Address
checkoutUrl: String
}Fields
| Field | Type | Nullable | Description | Related Type |
|---|---|---|---|---|
id | String | Yes | Returns the id for this cart. | — |
createdAt | String | Yes | Date when this order was created in RFC 2822 format. | — |
customer | Customer | Yes | Customer linked to this order if any. | Customer |
discounts | [CartDiscount] | Yes | Returns the discounts applied to this cart. | CartDiscount |
tags | [String] | Yes | Returns the tags associated with this cart. | — |
subtotalPrice | Float | Yes | Returns the subtotal in customer’s currency. | — |
totalPrice | Float | Yes | Returns the total in customer’s currency. | — |
currency | String | Yes | Returns the currency for this cart. | — |
totalNetPrice | Float | Yes | Returns the net total in customer’s currency. | — |
totalTax | Float | Yes | Returns the total tax in customer’s currency. | — |
taxLines | [CartTaxLine] | Yes | Returns the tax lines for this cart. | CartTaxLine |
customerNote | String | Yes | Returns the customer note. | — |
paymentMethods | [CartPaymentMethod] | Yes | Returns the payment methods for this cart. | CartPaymentMethod |
paymentFee | Float | Yes | Returns the total payment fee in customer’s currency. | — |
shippingMethods | [CartShippingMethod] | Yes | Returns the shipping methods for this cart. | CartShippingMethod |
shippingPrice | Float | Yes | Returns the total shipping costs in customer’s currency. | — |
lines | [CartLineItem] | Yes | Returns the items in this cart. | CartLineItem |
physicalLines | [CartLineItem] | Yes | Returns the physical items in this cart. | CartLineItem |
lineCount | Int | Yes | Returns the number of items in this cart. | — |
shippingAddress | Address | Yes | Returns the shipping address for this cart. | Address |
billingAddress | Address | Yes | Returns the billing address for this cart. | Address |
checkoutUrl | String | Yes | Returns the checkout URL for this cart. | — |
Relationships
- customer: Links to the
Customerobject representing the customer associated with the cart, if any. - discounts: An array of
CartDiscountobjects representing discounts applied to the cart. - taxLines: An array of
CartTaxLineobjects detailing tax breakdowns for the cart. - paymentMethods: An array of
CartPaymentMethodobjects describing available payment methods. - shippingMethods: An array of
CartShippingMethodobjects describing available shipping options. - lines and physicalLines: Arrays of
CartLineItemobjects representing all items and physical items in the cart respectively. - shippingAddress and billingAddress:
Addressobjects representing the respective addresses for the cart.
These relationships allow traversal from the cart to related entities, enabling detailed queries about the cart’s contents, pricing, and fulfillment.
Usage Examples
Basic Query
Fetch a cart by its ID with key summary fields:
query GetCart {
cart(id: "12345") {
id
createdAt
subtotalPrice
totalPrice
currency
lineCount
checkoutUrl
}
}Field Selection
Retrieve detailed pricing, discounts, and tags for a cart:
query CartPricingDetails {
cart(id: "12345") {
subtotalPrice
totalNetPrice
totalTax
totalPrice
discounts {
code
amount
}
tags
}
}Nested Queries
Access nested objects such as customer info, shipping address, and cart line items:
query CartWithDetails {
cart(id: "12345") {
id
customer {
id
firstName
lastName
email
}
shippingAddress {
address1
city
postalCode
country
}
lines {
productId
quantity
title
variantId
price
}
}
}Filtering and Sorting
Since the Cart type itself does not expose filtering or sorting fields, these operations are typically performed at the query level (e.g., when querying multiple carts). However, you can filter line items client-side by examining fields such as physicalLines to isolate physical products.
Example: Query only physical items in the cart:
query PhysicalItemsInCart {
cart(id: "12345") {
physicalLines {
productId
quantity
title
price
}
}
}Pagination is not directly applicable to the Cart type fields as defined.
Implements
The Cart type does not implement any interfaces.
Connections
The Cart object connects to multiple related types through its fields:
customer→Customerdiscounts→[CartDiscount]taxLines→[CartTaxLine]paymentMethods→[CartPaymentMethod]shippingMethods→[CartShippingMethod]linesandphysicalLines→[CartLineItem]shippingAddressandbillingAddress→Address
These connections enable rich, nested queries to retrieve comprehensive cart data.
Related Types
- Customer: Represents the customer associated with the cart.
- CartDiscount: Represents discounts applied to the cart.
- CartTaxLine: Represents tax details for the cart.
- CartPaymentMethod: Represents payment options available for the cart.
- CartShippingMethod: Represents shipping options available for the cart.
- CartLineItem: Represents individual items in the cart.
- Address: Represents shipping and billing addresses.
Best Practices
- Selective Field Queries: Request only the fields you need to optimize performance and reduce payload size.
- Use Nested Queries: Leverage nested queries to fetch related data (e.g., customer info, line items) in a single request.
- Cache Results: Cache cart data where appropriate to minimize repeated requests, especially for frequently accessed carts.
- Handle Nullability: Since many fields are optional, always implement null checks in client code to avoid runtime errors.
- Monitor Pricing Fields: Use
subtotalPrice,totalNetPrice,totalTax, andtotalPriceto accurately display pricing breakdowns. - Use
physicalLinesfor Fulfillment: When processing shipments, use thephysicalLinesfield to identify shippable items.
Notes
- All monetary fields (
subtotalPrice,totalPrice,totalNetPrice,totalTax,paymentFee,shippingPrice) are returned in the customer’s currency. - The
createdAtfield follows the RFC 2822 date format. - The
checkoutUrlprovides a direct link to the checkout page for the cart. - The API currently requires no authentication; however, this may change in future versions.
- Since many fields are optional, clients should gracefully handle missing data.
- There are no computed or derived fields explicitly defined on the
Carttype beyond the provided fields. - No field arguments are defined on the
Carttype fields. - Performance can be improved by limiting nested queries to only necessary related objects.
- For carts with a large number of line items, consider paginating or filtering client-side as the API does not provide built-in pagination on the
linesfield.