Skip to main content
Version: 1.0.0

UpdateCartItemsMutation

Description

Updates the quantities of one or more items in the cart. This mutation allows you to change the quantity of existing products in the cart based on their SKUs.

Endpoint

mutation updateCartItems($cartId: String!, $items: [UpdateCartItemInput!]) {
updateCartItems(cartId: $cartId, items: $items) {
# Return fields
}
}

Arguments

ArgumentTypeRequiredDescription
cartIdStringYesThe unique identifier of the cart to update. This ID is obtained from createGuestCart or createCustomerCart mutations.
items[UpdateCartItemInput]NoA list of items to update in the cart.

UpdateCartItemInput

FieldTypeRequiredDescription
skuStringYesThe SKU of the product to update.
qtyIntYesThe new quantity for the product. Set to 0 to remove the item from the cart.

Return Values

The mutation 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, with updated quantities.
selected_shipping_methodObjectThe selected shipping method for the cart.
selected_payment_methodObjectThe selected payment method for the cart.
totalsObjectCart totals information, recalculated after updating the items.

For detailed information about the structure of these fields, refer to the CartQuery documentation.

Usage Example

mutation {
updateCartItems(
cartId: "abc123",
items: [
{
sku: "product-123",
qty: 3
},
{
sku: "product-456",
qty: 1
}
]
) {
items {
id
quantity
name
sku
row_total {
value
currency
}
}
totals {
grand_total {
value
currency
}
}
}
}

Example Response

{
"data": {
"updateCartItems": {
"items": [
{
"id": "123",
"quantity": 3,
"name": "Sample Product",
"sku": "product-123",
"row_total": {
"value": 59.97,
"currency": "USD"
}
},
{
"id": "456",
"quantity": 1,
"name": "Another Product",
"sku": "product-456",
"row_total": {
"value": 29.99,
"currency": "USD"
}
}
],
"totals": {
"grand_total": {
"value": 89.96,
"currency": "USD"
}
}
}
}
}

Notes

  • If you set the quantity of an item to 0, it will be removed from the cart.
  • If the SKU does not exist in the cart, the update for that item will be ignored.
  • After updating items, the cart totals will be recalculated.
  • If you want to remove an item from the cart, you can either use this mutation with a quantity of 0, or use the removeItemFromCart mutation.
  • Stock validation may be performed if catalog stock management is enabled. An error will be thrown if the requested quantity exceeds available stock.