The Greatest Sale - Extra 20%

NATPAT 的集合页

sale
商品数
13
在投广告
0
深度
发布
2024/05/25

关于

.hero-content-top .page-title,.collection-hero-container .custom-breadcrumbs li a,.collection-hero-container .custom-breadcrumbs li {color: #fff;} $(document).ready(function() { const productId = 43942367920172; const desiredQuantity = 1; function addOrUpdateProduct() { fetch('/cart.js') .then(response => response.json()) .then(cart => { const existingItem = cart.items.find(item => item.id === productId); if (existingItem) { if (existingItem.quantity !== desiredQuantity) { updateCart({ [productId]: desiredQuantity }); } } else { addProductToCart(productId, desiredQuantity); } }) .catch(error => console.error("Error fetching the cart:", error)); } function addProductToCart(productId, quantity) { fetch('/cart/add.js', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ id: productId, quantity: quantity, }), }) .then(response => response.json()) .then(data => { console.log("Product added to cart:", data); }) .catch(error => console.error("Error adding product to cart:", error)); } function updateCart(updates) { fetch('/cart/update.js', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ updates }), }) .then(response => response.json()) .then(data => { console.log("Cart updated:", data); }) .catch(error => console.error("Error updating the cart:", error)); } // Function to trigger when a product is added to the cart function productAddedToCart(variantId) { // Your specific function logic here console.log('Product with variant ID ' + variantId + ' added to cart.'); // Add your custom actions, like displaying a success message, tracking events, etc. } $('.quick-add__submit').on('click', function(event) { var $form = $(this).closest('form'); var variantId = $form.find('input[name="id"]').val(); var selectedQuantity = parseInt($form.find('.single-option-selector__radio:checked').closest('label').text().replace(/\D/g, '')); if (selectedQuantity !== 1) { Shopify.Checkout.addItem(variantId, selectedQ