Envero Diamond List
(function(d, w) {
function observeAddToCart() {
jQuery(w).on('ds.addtocart', function(event, data) {
jQuery.ajax({
//This is the API to where to POST the data to.
url: '/api/add_to_inventory_and_add_to_cart',
type: 'POST',
data: data
}).done(function(res) {
//On success of the API call
w.location = '/success';
}).fail(function(res) {
//On fail of the API call
alert(res.message);
});
});
}
if (d.addEventListener) {
d.addEventListener('ds.ready', function() {
observeAddToCart();
}, false);
} else if (d.attachEvent) {
d.documentElement.attachEvent('onpropertychange', function(event) {
if (event.propertyName === 'ds.ready')
observeAddToCart();
});
}
}(document, window));