Repository: saleor/saleor

Issue:
Add list of invalid steps to checkout summary



Discussion:

Resolving patch:
diff --git a/saleor/cart/__init__.py b/saleor/cart/__init__.py
--- a/saleor/cart/__init__.py
+++ b/saleor/cart/__init__.py
@@ -27,15 +27,31 @@ def get_delivery_methods(self, **kwargs):
         '''
         raise NotImplementedError()
 
+    def _get_cheapest_delivery_method(self, **kwargs):
+        if self.delivery_method:
+            return (self.delivery_method,
+                    self.delivery_method.get_price_per_item(**kwargs))
+        methods = self.get_delivery_methods()
+        prices = ((method.get_price_per_item(**kwargs), method)
+                  for method in methods)
+        cheapest_price, cheapest_method = min(prices)
+        return cheapest_method, cheapest_price
+
     def get_delivery_total(self, **kwargs):
         '''
         Method returns price from the self.delivery_method or lowest price
         from delivery methods.
         '''
-        if self.delivery_method:
-            return self.delivery_method.get_price_per_item(**kwargs)
-        methods = self.get_delivery_methods()
-        return min(method.get_price_per_item(**kwargs) for method in methods)
+        method, price = self._get_cheapest_delivery_method(**kwargs)
+        return price
+
+    def get_delivery_method(self, **kwargs):
+        '''
+        Method returns price from the self.delivery_method or lowest price
+        from delivery methods.
+        '''
+        method, price = self._get_cheapest_delivery_method(**kwargs)
+        return method
 
     def get_total_with_delivery(self, **kwargs):
         return self.get_total() + self.get_delivery_total()
diff --git a/saleor/checkout/__init__.py b/saleor/checkout/__init__.py
--- a/saleor/checkout/__init__.py
+++ b/saleor/checkout/__init__.py
@@ -21,7 +21,7 @@ def __init__(self, *args, **kwargs):
                      'groups': defaultdict(dict), 'summary': False})
 
 
-class CheckoutGroup(namedtuple('CheckoutGroup', 'group, items')):
+class CheckoutGroup(namedtuple('CheckoutGroup', 'step, group, items')):
 
     def __iter__(self):
         return iter(self.items)
@@ -48,7 +48,8 @@ def __init__(self, request):
     def generate_groups(self, cart):
         self.items = CartPartitioner(cart)
         self.groups = []
-        self.steps = [BillingAddressStep(self, self.request)]
+        self.billing = BillingAddressStep(self, self.request)
+        self.steps = [self.billing]
         for index, delivery_group in enumerate(self.items):
             if isinstance(delivery_group, DigitalGroup):
                 step_class = DigitalDeliveryStep
@@ -59,7 +60,7 @@ def generate_groups(self, cart):
             step_group = self.get_group(str(step))
             if 'delivery_method' in step_group:
                 delivery_group.delivery_method = step_group['delivery_method']
-            group = CheckoutGroup(step_group, delivery_group)
+            group = CheckoutGroup(step, step_group, delivery_group)
             self.groups.append(group)
             self.steps.append(step)
         self.steps.append(SummaryStep(self, self.request))
diff --git a/saleor/checkout/steps.py b/saleor/checkout/steps.py
--- a/saleor/checkout/steps.py
+++ b/saleor/checkout/steps.py
@@ -30,7 +30,7 @@ def add_to_order(self, order):
         raise NotImplementedError()
 
     def process(self, extra_context=None):
-        context = extra_context or {}
+        context = dict(extra_context or {})
         context['checkout'] = self.checkout
         return super(BaseCheckoutStep, self).process(extra_context=context)
 
@@ -77,7 +77,7 @@ def validate(self):
             raise InvalidData(e.messages)
 
     def process(self, extra_context=None):
-        context = extra_context or {}
+        context = dict(extra_context or {})
         context['form'] = self.forms['address']
         context['address_book'] = self.address_book
         return super(BaseAddressStep, self).process(extra_context=context)
@@ -201,7 +201,8 @@ def is_default_address(self, entry, user):
                 user.default_shipping_address_id == entry.id)
 
     def process(self, extra_context=None):
-        context = extra_context or {}
+        context = dict(extra_context or {})
+        context['items'] = self.delivery_group
         context['delivery_form'] = self.forms['delivery']
         return super(ShippingStep, self).process(extra_context=context)
 
@@ -244,8 +245,9 @@ def add_to_order(self, order):
         group.add_items_from_partition(self.delivery_group)
 
     def process(self, extra_context=None):
-        context = extra_context or {}
+        context = dict(extra_context or {})
         context['form'] = self.forms['email']
+        context['items'] = self.delivery_group
         return super(DigitalDeliveryStep, self).process(extra_context=context)
 
 
@@ -260,7 +262,9 @@ def __unicode__(self):
         return 'Summary'
 
     def process(self, extra_context=None):
-        response = super(SummaryStep, self).process(extra_context)
+        context = dict(extra_context or {})
+        context['all_steps_valid'] = self.forms_are_valid()
+        response = super(SummaryStep, self).process(context)
         if not response:
             with transaction.atomic():
                 order = self.checkout.create_order()


Test patch: