Fix items not removing from cart
parent
1b4a823d1d
commit
43857f9b07
|
@ -613,17 +613,24 @@ function deleteFromCart(element){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/product/removefromcart',
|
url: '/product/removefromcart',
|
||||||
data: {cart_index: element}
|
data: {cart_index: element.attr('data-id')}
|
||||||
})
|
})
|
||||||
.done(function(msg){
|
.done(function(msg){
|
||||||
$('#cart-count').text(msg.totalCartItems);
|
$('#cart-count').text(msg.totalCartItems);
|
||||||
if(msg.totalCartItems === 0){
|
if(msg.totalCartItems === 0){
|
||||||
|
$(element).closest('.cart-row').hide('slow', function(){
|
||||||
|
$(element).closest('.cart-row').remove();
|
||||||
|
});
|
||||||
|
$('.cart-contents-shipping').hide('slow', function(){
|
||||||
|
$('.cart-contents-shipping').remove();
|
||||||
|
});
|
||||||
showNotification(msg.message, 'success');
|
showNotification(msg.message, 'success');
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
window.location = '/';
|
window.location = '/';
|
||||||
}, 3700);
|
}, 3700);
|
||||||
}else{
|
}else{
|
||||||
showNotification(msg.message, 'success', true);
|
$(element).closest('.cart-row').hide('slow', function(){ $(element).closest('.cart-row').remove(); });
|
||||||
|
showNotification(msg.message, 'success');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.fail(function(msg){
|
.fail(function(msg){
|
||||||
|
@ -644,8 +651,8 @@ function slugify(str){
|
||||||
}
|
}
|
||||||
|
|
||||||
function cartUpdate(element){
|
function cartUpdate(element){
|
||||||
if($(element).val() === 0){
|
if($(element).val() < 1){
|
||||||
deleteFromCart($(element).attr('data-id'));
|
deleteFromCart($(element));
|
||||||
}else{
|
}else{
|
||||||
if($(element).val() !== ''){
|
if($(element).val() !== ''){
|
||||||
updateCart();
|
updateCart();
|
||||||
|
@ -662,8 +669,8 @@ function updateCart(){
|
||||||
itemQuantity: $(this).val(),
|
itemQuantity: $(this).val(),
|
||||||
productId: $(this).attr('data-id')
|
productId: $(this).attr('data-id')
|
||||||
};
|
};
|
||||||
if($(this).val() === '0'){
|
if($(this).val() < 0){
|
||||||
deleteFromCart($(this).attr('data-id'));
|
deleteFromCart($(this));
|
||||||
}else{
|
}else{
|
||||||
cartItems.push(item);
|
cartItems.push(item);
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -184,7 +184,7 @@ router.post('/product/removefromcart', (req, res, next) => {
|
||||||
async.each(req.session.cart, (item, callback) => {
|
async.each(req.session.cart, (item, callback) => {
|
||||||
if(item){
|
if(item){
|
||||||
if(item.productId === req.body.cart_index){
|
if(item.productId === req.body.cart_index){
|
||||||
req.session.cart.splice(req.session.cart.indexOf(item), 1);
|
req.session.cart = _.pull(req.session.cart, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
callback();
|
callback();
|
||||||
|
|
Loading…
Reference in New Issue