Skip to main content

validateCart

Adds, removes, or updates items in a given shopping cart.

The validateCart mutation compares the cart displayed in the UI with the cart kept in the ecommerce platform. If differences are detected, it updates the cart stored on the platform and then returns the adjusted data. Otherwise, it returns null.

Usage​

Arguments​

cart*IStoreCart!
Description

Shopping cart to be validated (IStoreCart with orderNumber and acceptedOffer)

orderNumber*String!
Description

ID of the order in the ecommerce platform.

acceptedOffer*[IStoreOffer!]
Description

Array of offers (IStoreOffer) that are in the UI cart.

Fields​

Below you can see a list of fields that can be returned by the validateCart mutation. Click on the links to learn more details about each field.

Mutation structure​

mutation {
validateCart (
cart: {
order: {
orderNumber: # String!,
acceptedOffer: [
{
# IStoreOffer fields
}
]
}
}
)
{
order {
orderNumber: # String!,
acceptedOffer: [
{
# StoreOffer fields
}
]
}
}
}

Shopping cart flow​

When you use validateCart for the first interaction of a given user (e.g., adding the first product), you should send an empty orderNumber ("").

You will receive a new orderNumber in the response. Make sure to save it and use it in the following requests for that same cart.

To remove an item from a cart, you should send the item in the acceptedOffer array, but with a quantity of 0.

caution

Note that sending an empty acceptedOffer array will not empty the cart. You must send the array with the existing products, with quantity: 0.

Examples​

  • Adding the first item to the cart.
mutation validateCart($cart: IStoreCart!) {
validateCart (
cart: $cart
) {
order {
orderNumber,
acceptedOffer {
price,
quantity,
seller {
identifier
},
itemOffered {
name,
sku,
description,
image {
url,
alternateName
}
}
}
},
messages {
text,
status
}
}
}
  • Removing an item from the cart.
mutation validateCart($cart: IStoreCart!) {
validateCart (
cart: $cart
) {
order {
orderNumber,
acceptedOffer {
price,
quantity,
seller {
identifier
},
itemOffered {
name,
sku,
description,
image {
url,
alternateName
}
}
}
},
messages {
text,
status
}
}
}

Didn't find your answers? Ask the Community. For documentation suggestions, submit your feedback.

JOIN THE COMMUNITY