document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('.sqs-add-to-cart-button').forEach(button => {
button.addEventListener('click', function(event) {
event.preventDefault();
const productID = button.getAttribute('data-item-id');
fetch('/cart/add', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({ lineItems: [{ productId: productID, quantity: 1 }] }),
})
.then(response => response.json())
.then(data => {
window.location.href = '/checkout';
})
.catch(error => console.error('Error:', error));
});
});
});