if (window.eComEventTarget) { window.eComEventTarget.addEventListener('wishlist:add', function (event) { if (XMLHttpRequest) { var xhr = new XMLHttpRequest(), product = event.detail.product, targetUrl = 'https://www.classicopals.com.au/epages/classicopal.sf' + '?ViewAction=JSONViewResponse&ChangeAction=JSONAddItemToShoppingList', data = { 'ProductGUID': product.productId, 'Quantity': product.quantity, 'LineItemGUID': event.detail.lineItemId, 'LocaleID' : event.detail.locale }; xhr.open('POST', targetUrl, true); xhr.setRequestHeader('Content-Type', 'application/json') xhr.addEventListener('load', function() { if (xhr.status < 200 || xhr.status >= 300) { console.warn(xhr.statusText, xhr.responseText); } else { var response = JSON.parse(xhr.responseText) if (response.success) { window.eComEventTarget.dispatchEvent(new CustomEvent('wishlist:success-' + response.productId, {'detail': response})); } else if (response.reason === 'nouser'){ window.eComEventTarget.dispatchEvent(new CustomEvent('wishlist:nouser-' + response.productId, {'detail': response})); } else { console.warn(xhr.statusText, xhr.responseText); } } }); xhr.send(JSON.stringify(data)); } }) }