Skip to content

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

Remove forms with none quantity

Michal Ociepka0079dcfeebe9
diff --git a/cart/forms.py b/cart/forms.py
index 6664cd709d..42bff34c26 100644
--- a/cart/forms.py
+++ b/cart/forms.py
@@ -69,8 +69,10 @@ class ReplaceCartLineFormSet(BaseFormSet):
def __init__(self, *args, **kwargs):
self.cart = kwargs.pop('cart')
- kwargs['initial'] = [{'quantity': cart_line.get_quantity()}
- for cart_line in self.cart]
+ kwargs['initial'] = [{'quantity':cart_line.get_quantity()}
+ for cart_line in self.cart
+ if cart_line.get_quantity()]
+
super(ReplaceCartLineFormSet, self).__init__(*args, **kwargs)
def _construct_form(self, i, **kwargs):
diff --git a/cart/views.py b/cart/views.py
index 0f85eafa97..2c03cc2388 100755
--- a/cart/views.py
+++ b/cart/views.py
@@ -1,5 +1,6 @@
from . import get_cart_from_request
from .forms import ReplaceCartLineFormSet
+from django.shortcuts import redirect
from django.template.response import TemplateResponse
def index(request):
@@ -9,6 +10,7 @@ def index(request):
if formset.is_valid():
formset.save()
+ return redirect('cart:index')
return TemplateResponse(request, 'cart/index.html', {
'cart': cart,