document.addEventListener('DOMContentLoaded', function() {
let beerTag = 'beer'; // The tag used to identify beer items
let depositProductId = 'SGR'; // Replace with the bottle deposit product's ID
let depositPrice = 0.5; // Replace with your deposit amount
function updateDeposit() {
fetch('/cart.js')
.then(response => response.json())
.then(cart => {
let beerQuantity = cart.items
.filter(item => item.product.tags.includes(beerTag))
.reduce((total, item) => total + item.quantity, 0);
let existingDeposit = cart.items.find(item => item.id === depositProductId);
if (beerQuantity > 0 && (!existingDeposit || existingDeposit.quantity !== beerQuantity)) {
fetch('/cart/change.js', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
id: depositProductId,
quantity: beerQuantity
})
});
}
});
}
updateDeposit();
});
Coșul dvs.
Continuați cumpărăturileCoșul dvs. este gol
Continuați cumpărăturileAi un cont?
Conectează-te pentru a finaliza comanda mai rapid.