Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix remove from cart function

weronkafe746bb0ded9
diff --git a/saleor/cart/views.py b/saleor/cart/views.py
index da52f27ac0..fcaea41f5d 100644
--- a/saleor/cart/views.py
+++ b/saleor/cart/views.py
@@ -73,7 +73,9 @@ def update(request, cart, variant_id):
form.save()
response = {'productId': variant_id,
'subtotal': 0,
- 'total': 0}
+ 'total': 0,
+ 'cart': cart.quantity,
+ 'cart_length': len(cart)}
updated_line = cart.get_line(form.cart_line.variant)
if updated_line:
response['subtotal'] = currencyfmt(
diff --git a/saleor/static/js/storefront.js b/saleor/static/js/storefront.js
index a5c5f3a346..74125b91f5 100644
--- a/saleor/static/js/storefront.js
+++ b/saleor/static/js/storefront.js
@@ -150,6 +150,7 @@ if (variantPicker) {
var $cartLine = $('.cart__line')
var $total = $('.cart-total')
+var $cartBadge = $('.navbar__brand__cart .badge')
$cartLine.each(function() {
var $quantityInput = $(this).find('#id_quantity')
var cartFormUrl = $(this).find('.form-cart').attr('action')
@@ -165,6 +166,7 @@ $cartLine.each(function() {
success: (response) => {
$subtotal.html(response.subtotal)
$total.html(response.total)
+ $cartBadge.html(response.cart)
$formError.html('')
},
error: (response) => {
@@ -179,7 +181,12 @@ $cartLine.each(function() {
method: 'POST',
data: {quantity: 0},
success: (response) => {
- location.reload()
+ if (response.cart_length >= 1) {
+ $(this).fadeOut()
+ $total.html(response.total)
+ } else {
+ location.reload()
+ }
}
})
})