A JavaScript object that is created for each Shopify Cart API Ajax request, where Liquid Ajax Cart keeps information about the request.
{
"endpoint": "/cart/add.js",
"requestBody": {"items": [{"id": 40934235668668, "quantity": 1}], "sections": "my-cart"},
"requestType": "add",
"info": {
"initiator": Element {},
"cancel": false
},
"responseData": {
"ok": true,
"status": 200,
"body": {…}
},
"extraResponseData": {
"ok": true,
"status": 200,
"body": {…}
}
}
endpointA Shopify Cart API endpoint URL of the request.
requestBodyPOST request, the requestBody is either a JSON or a FormData object to send to the Shopify Cart API endpoint.GET request, the requestBody is undefined.infoAn object to keep any additional data, that is set by the caller of a request.
When you make your request, you can add any properties you want.
There are only two reserved properties, initiator and cancel,
that you shouldn’t use for storing custom data.
info.initiatorWhen Liquid Ajax Cart executes a Shopify Cart API Ajax request that is initiated by a user action,
such as a submitting a product form, modifying cart item quantity input value, or clicking a “remove cart item” button,
Liquid Ajax Cart stores the HTMLElement object, that triggered the event, in the info.initiator property.
For example, if a user changes a cart item quantity input value with the data-ajax-cart-quantity-input attribute,
Liquid Ajax Cart intercepts the event and executes a /cart/change.js Shopify Cart API Ajax request.
Along with that, Liquid Ajax Cart attaches the input HTMLElement object to the info.initiator property.
If a Shopify Cart API Ajax request is initiated by a cart mutation function,
the info.initiator property has the string value mutation.
info.cancelIf the info.cancel is true, then the request won’t be executed and the responseData property won’t exist.
This lets you cancel a request
in a liquid-ajax-cart:request-start event listener.
responseDataA Shopify response to the request.
If the responseData.ok is true, it means the request was successful (status is in range 200—299).
The responseData is null if:
info.cancel property;fetchError property.extraResponseDataSometimes Liquid Ajax Cart performs an additional Shopify POST /cart/update.js request and puts the response to the extraResponseData property.
The additional request happens if:
/cart/add.js request that doesn’t return the cart state data — the additional /cart/update.js request will bring the updated cart state,/cart/update.js request will bring the rest sections HTML.fetchErrorIf the request failed and the response wasn’t received, for example because of internet connection, you’ll find the fetchError property:
{
"endpoint": "/cart/add.js",
"requestBody": {"items": [{"id": 40934235668668, "quantity": 1}], "sections": "my-cart"},
"requestType": "add",
"info": {},
"fetchError": {
"message": "Failed to fetch",
"stack": "TypeError: Failed to fetch\n at e.fetch (h..."
}
}
You can access a Request state object in liquid-ajax-cart:request-start
and liquid-ajax-cart:request-end event handlers.
In a liquid-ajax-cart:request-start event handler you can
modify the request by mutating the requestBody object,
append custom data or cancel a request by mutating the info object.
When initiating a Shopify Cart API Ajax request through the methods
get,
add,
change,
update,
clear
of the liquidAjaxCart object,
you can attach custom data by using the info option and get the Request state object
in the firstCallback, lastCallback callback functions.