There are 2 types of events to which one can subscribe namely - beforeCartRequest and afterCartRequest . These events will be triggered for any one of these intercepted cart type requests - /cart/add, /cart/change, /cart/update or /cart/clear.
In order to subscribe to these events, one can use window.EasyGift.Events.subscribe function. There are 2 required arguments to use this function:
window.EasyGift.Events.subscribe(<type>, <callback_function>);
Here is an example to subscribe to each of these events:
window.EasyGift.Events.subscribe("beforeCartRequest", data => alert('before cart request interception'));
window.EasyGift.Events.subscribe("afterCartRequest", data => alert('after cart request interception'));
For the callback function of both the events, the response is an object. This response object has these various fields:
As mentioned, the type here can be of 3 types for both the events. Here are the sample responses for each type:
{
"url": "/cart/add",
"type": "SUBMIT",
"method": "POST",
"payload": {
"id": "98761234512345",
"quantity": "1"
}
}
{
"url": "/cart/add.js",
"type": "XHR",
"method": "POST",
"payload": {
"id": "98761234512345",
"quantity": "1"
}
}
{
"url": "/cart/add",
"type": "FETCH",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"payload": {
"id": "98761234512345",
"quantity": "1"
}
}