You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
|
|
$(document).ready( () => {
|
|
console.log('Load component - cart')
|
|
|
|
const component = $('.component-cart')
|
|
|
|
if(component.length) {
|
|
const items = component.find('.list .item')
|
|
const total = component.find('.total')
|
|
const price = total.find('.price')
|
|
|
|
items.each( (i,e) => {
|
|
const item = $(e)
|
|
const pid = item.data('pid')
|
|
const remove = item.find('.remove')
|
|
|
|
remove.off('.click').on('click.click', () => {
|
|
Apis.removeFromCart(pid).then( (data) => {
|
|
if(data.cart.length) {
|
|
const headerCart = $('.component-header .cart-cta .counter')
|
|
if(headerCart.length) {
|
|
headerCart.text(data.cart.length)
|
|
}
|
|
item.fadeOut()
|
|
let total = 0
|
|
$.each(data.cart, (i, e) => {
|
|
total += parseFloat(e.price) * parseInt(e.qty)
|
|
})
|
|
price.text(new Intl.NumberFormat('it-IT', { style: 'currency', currency: 'EUR'}).format(total))
|
|
} else {
|
|
window.location = '/acquistare'
|
|
}
|
|
}).catch( (error) => {
|
|
console.error(error)
|
|
})
|
|
})
|
|
|
|
})
|
|
}
|
|
})
|