Skip to content

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

check if request is ajax

TOMEKd20922d1b638
diff --git a/saleor/checkout/views/__init__.py b/saleor/checkout/views/__init__.py
index 09e2478102..bcec3ac07b 100644
--- a/saleor/checkout/views/__init__.py
+++ b/saleor/checkout/views/__init__.py
@@ -200,6 +200,9 @@ def clear_cart(request, cart):
"""Clear cart"""
from ..utils import update_cart_quantity
+ if not request.is_ajax():
+ return redirect('cart:index')
+
lines = cart.lines.all()
for line in lines:
line.delete()
diff --git a/saleor/static/js/components/cart.js b/saleor/static/js/components/cart.js
index 73f1389d84..207b16dfd4 100644
--- a/saleor/static/js/components/cart.js
+++ b/saleor/static/js/components/cart.js
@@ -59,7 +59,7 @@ export default $(document).ready((e) => {
});
$('.cart__clear').click((e) => {
$.ajax({
- url: $('.cart_clear').attr('action'),
+ url: $('.cart__clear').attr('action'),
method: 'POST',
data: {},
success: (response) => {