setupActionButtons() {
const addToCartButtons = this.querySelectorAll('.ai-add-to-cart-aelrpotrzc0zxsfpetaigenblocke898605ww7wun');
const buyNowButtons = this.querySelectorAll('.ai-buy-now-aelrpotrzc0zxsfpetaigenblocke898605ww7wun');
addToCartButtons.forEach(button => {
button.addEventListener('click', (e) => {
const productIndex = e.target.dataset.productIndex;
const variantId = this.selectedVariants[productIndex];
if (!variantId) {
this.showNotification();
return;
}
this.addToCart(variantId);
});
});
buyNowButtons.forEach(button => {
button.addEventListener('click', (e) => {
const productIndex = e.target.dataset.productIndex;
const variantId = this.selectedVariants[productIndex];
if (!variantId) {
this.showNotification();
return;
}
this.buyNow(variantId);
});
});
}
setupNotification() {
const closeButton = this.querySelector('.ai-product-notification__close-aelrpotrzc0zxsfpetaigenblocke898605ww7wun');
if (closeButton) {
closeButton.addEventListener('click', () => {
this.hideNotification();
});
}
}
showNotification() {
const notification = this.querySelector('.ai-product-notification-aelrpotrzc0zxsfpetaigenblocke898605ww7wun');
if (notification) {
notification.classList.add('show');
}
}
hideNotification() {
const notification = this.querySelector('.ai-product-notification-aelrpotrzc0zxsfpetaigenblocke898605ww7wun');
if (notification) {
notification.classList.remove('show');
}
}
addToCart(variantId) {
fetch('/cart/add.js', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
id: variantId,
quantity: 1
})
})
.then(response => response.json())
.then(data => {
window.location.href = '/cart';
})
.catch(error => {
console.error('Error adding to cart:', error);
});
}
buyNow(variantId) {
fetch('/cart/add.js', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
id: variantId,
quantity: 1
})
})
.then(response => response.json())
.then(data => {
window.location.href = '/checkout';
})
.catch(error => {
console.error('Error:', error);
});
}
}
customElements.define('product-showcase-grid-aelrpotrzc0zxsfpetaigenblocke898605ww7wun', ProductShowcaseGridaelrpotrzc0zxsfpetaigenblocke898605ww7wun);
})();