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!
Shopping cart to be validated (IStoreCart
with orderNumber
and acceptedOffer
)
orderNumber
*String!
ID of the order in the ecommerce platform.
acceptedOffer
*[IStoreOffer!]
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.
validateCart
: StoreCartorder
: StoreOrder!orderNumber
: String!acceptedOffer
: [ StoreOffer!]!Offer information. Check StoreOffer to see all possible fields.
messages
: [ StoreCartMessage !]!text
: String!status
: StoreStatus!
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
.
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
- Variables
- Response
mutation validateCart($cart: IStoreCart!) {
validateCart(cart: $cart) {
order {
orderNumber
acceptedOffer {
price
quantity
seller {
identifier
}
itemOffered {
name
sku
description
image {
url
alternateName
}
}
}
}
messages {
text
status
}
}
}
{
"cart": {
"order": {
"orderNumber": "",
"acceptedOffer": [
{
"price": 130,
"listPrice": 150,
"seller": {
"identifier": "1"
},
"quantity": 1,
"itemOffered": {
"sku": "99988211",
"image": [
{
"url": "https://storeframework.vtexassets.com/arquivos/ids/190901/unsplash-headphone.jpg?v=637800115948430000",
"alternateName": "aedleheadphone"
}
],
"name": "Leather"
}
}
]
}
}
}
{
"data": {
"validateCart": {
"order": {
"orderNumber": "96fbf6fba3094a918c1f1552ca68f008",
"acceptedOffer": [
{
"price": 130,
"quantity": 1,
"seller": {
"identifier": "1"
},
"itemOffered": {
"name": "Leather",
"sku": "99988211",
"description": "Aedle VK-1 L Headphone",
"image": [
{
"url": "https://storeframework.vtexassets.com/arquivos/ids/190901/unsplash-headphone.jpg?v=637800115948430000",
"alternateName": "aedleheadphone"
}
]
}
}
]
},
"messages": []
}
}
}
- Removing an item from the cart.
- Mutation
- Variables
- Response
mutation validateCart($cart: IStoreCart!) {
validateCart(cart: $cart) {
order {
orderNumber
acceptedOffer {
price
quantity
seller {
identifier
}
itemOffered {
name
sku
description
image {
url
alternateName
}
}
}
}
messages {
text
status
}
}
}
{
"cart": {
"order": {
"orderNumber": "96fbf6fba3094a918c1f1552ca68f008",
"acceptedOffer": [
{
"price": 130,
"listPrice": 150,
"seller": {
"identifier": "1"
},
"quantity": 0,
"itemOffered": {
"sku": "99988211",
"image": [
{
"url": "https://storeframework.vtexassets.com/arquivos/ids/190901/unsplash-headphone.jpg?v=637800115948430000",
"alternateName": "aedleheadphone"
}
],
"name": "Leather"
}
}
]
}
}
}
{
"data": {
"validateCart": {
"order": {
"orderNumber": "96fbf6fba3094a918c1f1552ca68f008",
"acceptedOffer": []
},
"messages": []
}
}
}