Skip to content

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

Make checkout more functional

Patryk Zawadzki4863e0947f8b
diff --git a/saleor/cart/__init__.py b/saleor/cart/__init__.py
index 2d86f2421c..215d880da4 100755
--- a/saleor/cart/__init__.py
+++ b/saleor/cart/__init__.py
@@ -27,15 +27,31 @@ class BaseGroup(list, ItemSet):
'''
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
index 9c12d810ed..abc94e92ba 100644
--- a/saleor/checkout/__init__.py
+++ b/saleor/checkout/__init__.py
@@ -21,7 +21,7 @@ class CheckoutStorage(dict):
'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 @@ class Checkout(ProcessManager):
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 @@ class Checkout(ProcessManager):
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/templates/checkout/digitaldelivery.html b/saleor/checkout/templates/checkout/digitaldelivery.html
index 12412c25df..fe2b5f0246 100644
--- a/saleor/checkout/templates/checkout/digitaldelivery.html
+++ b/saleor/checkout/templates/checkout/digitaldelivery.html
@@ -1,23 +1,35 @@
{% extends "checkout/details.html" %}
-{% load i18n %}
+
{% load as_horizontal_form from bootstrap %}
+{% load i18n %}
+{% load gross from prices %}
{% block step_info %}
- <h3>{% trans "Please provide an address for the following items:" %}</h3>
- <table class="table table-striped">
- <thead>
- <tr>
- <th class="col-sm-12">{% trans "Name" %}</th>
- </tr>
- </thead>
- <tbody>
- {% for item in items %}
- <tr>
- <td class="col-sm-12">{{ item.product }}{% if item.quantity != 1 %} <em>×{{ item.quantity }}</em>{% endif %}</td>
- </tr>
- {% endfor %}
- </tbody>
- </table>
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ {% trans "Delivery group" %}
+ </div>
+ <div class="panel-body">
+ <table class="table table-striped">
+ <thead>
+ <tr>
+ <th class="col-sm-4">{% trans "Name" %}</th>
+ <th class="col-sm-2">{% trans "Price" %}</th>
+ <th class="col-sm-2">{% trans "Subtotal" %}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for item in items %}
+ <tr>
+ <td class="col-sm-4">{{ item.product }}{% if item.quantity != 1 %} <em>×{{ item.quantity }}</em>{% endif %}</td>
+ <td class="col-sm-2">{% gross item.get_price_per_item %}</td>
+ <td class="col-sm-2">{% gross item.get_total %}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </div>
+ </div>
<hr>
{% endblock %}
diff --git a/saleor/checkout/templates/checkout/shipping.html b/saleor/checkout/templates/checkout/shipping.html
index 2e8d75dafa..4f79ec04a2 100644
--- a/saleor/checkout/templates/checkout/shipping.html
+++ b/saleor/checkout/templates/checkout/shipping.html
@@ -5,21 +5,31 @@
{% load i18n %}
{% block step_info %}
- <h3>{% trans "Please provide shipping information for the following items:" %}</h3>
- <table class="table table-striped">
- <thead>
- <tr>
- <th class="col-sm-12">{% trans "Name" %}</th>
- </tr>
- </thead>
- <tbody>
- {% for item in items %}
- <tr>
- <td class="col-sm-12">{{ item.product }}{% if item.quantity != 1 %} <em>×{{ item.quantity }}</em>{% endif %}</td>
- </tr>
- {% endfor %}
- </tbody>
- </table>
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ {% trans "Delivery group" %}
+ </div>
+ <div class="panel-body">
+ <table class="table table-striped">
+ <thead>
+ <tr>
+ <th class="col-sm-4">{% trans "Name" %}</th>
+ <th class="col-sm-2">{% trans "Price" %}</th>
+ <th class="col-sm-2">{% trans "Subtotal" %}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for item in items %}
+ <tr>
+ <td class="col-sm-4">{{ item.product }}{% if item.quantity != 1 %} <em>×{{ item.quantity }}</em>{% endif %}</td>
+ <td class="col-sm-2">{% gross item.get_price_per_item %}</td>
+ <td class="col-sm-2">{% gross item.get_total %}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </div>
+ </div>
<hr>
{% endblock %}
diff --git a/saleor/checkout/templates/checkout/summary.html b/saleor/checkout/templates/checkout/summary.html
index 84a6b9c16a..df8ccc6e5b 100644
--- a/saleor/checkout/templates/checkout/summary.html
+++ b/saleor/checkout/templates/checkout/summary.html
@@ -1,65 +1,114 @@
{% extends "checkout/details.html" %}
{% load gross from prices %}
+{% load tax from prices %}
{% load i18n %}
{% block forms %}
- <h3>{% trans "Billing address" %}</h3>
- {% if checkout.billing_address %}
- <address>{% include "userprofile/snippets/address-details.html" with address=checkout.billing_address %}</address>
- {% else %}
- <p>{% trans "No address given yet." %}</p>
- {% endif %}
+ <div class="row">
+ <div class="col-sm-6">
+ <h3>{% trans "Order details" %}</h3>
- <h3>{% trans "Order details" %}</h3>
+ {% with total=checkout.get_total %}
+ <p>
+ {% trans "Order total" %}:
+ <strong>{% gross checkout.get_total %}</strong>
+ {% if total.gross %}
+ ({% blocktrans with tax=total.tax|floatformat:2 currency=total.currency %}includes {{ tax }} <span class="currency">{{ currency }}</span> tax{% endblocktrans %})
+ {% endif %}
+ </p>
+ {% endwith %}
+ </div>
+ <div class="col-sm-6">
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ {% trans "Billing address" %}
+ </div>
+ <div class="panel-body">
+ {% if checkout.billing_address %}
+ <address>{% include "userprofile/snippets/address-details.html" with address=checkout.billing_address %}</address>
+ {% else %}
+ <p class="text-danger">{% trans "No address given yet." %}</p>
+ {% endif %}
+ <p><a href="{{ checkout.billing.get_absolute_url }}">{% trans "Edit billing details" %}</a></p>
+ </div>
+ </div>
+ </div>
+ </div>
- <table class="table table-striped">
- <thead>
- <tr>
- <th class="col-sm-4">{% trans "Name" %}</th>
- <th class="col-sm-2">{% trans "Price" %}</th>
- <th class="col-sm-2">{% trans "Subtotal" %}</th>
- <th class="col-sm-2">{% trans "Shipping" %}</th>
- <th class="col-sm-2">{% trans "Total" %}</th>
- </tr>
- </thead>
- <tfoot>
- <tr>
- <td colspan="3" class="col-sm-8"></td>
- <th class="col-sm-2">{% trans "Total" %}:</th>
- <td class="col-sm-2">{% gross checkout.get_total %}</td>
- </tr>
- </tfoot>
- <tbody>
- {% for group in checkout.groups %}
- {% for item in group %}
- <tr>
- <td class="col-sm-4">{{ item.product }}{% if item.quantity != 1 %} <em>×{{ item.quantity }}</em>{% endif %}</td>
- <td class="col-sm-2">{% gross item.get_price_per_item %}</td>
- <td class="col-sm-2">{% gross item.get_total %}</td>
- {% if forloop.first %}
- <td rowspan="{{ group|length }}" class="col-sm-2">
- {% gross group.get_delivery_total %}
- {% if group.email %}
- <p>{{ group.email }}</p>
- {% elif group.address %}
- <p>
- {% include "userprofile/snippets/address-short.html" with address=group.address %}
- </p>
- {% endif %}
- </td>
- <td rowspan="{{ group|length }}" class="col-sm-2">{% gross group.get_total_with_delivery %}</td>
+ {% for group in checkout.groups %}
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ {% blocktrans with number=forloop.counter %}Delivery group #{{ number }}{% endblocktrans %}
+ </div>
+ <div class="panel-body">
+ <table class="table table-striped">
+ <thead>
+ <tr>
+ <th class="col-sm-4">{% trans "Name" %}</th>
+ <th class="col-sm-2">{% trans "Price" %}</th>
+ <th class="col-sm-2">{% trans "Subtotal" %}</th>
+ </tr>
+ </thead>
+ <tfoot>
+ <tr>
+ <th class="col-sm-4"></th>
+ <th class="col-sm-2">{% trans "Total" %}</th>
+ <th class="col-sm-2">{% gross group.get_total_with_delivery %}</th>
+ </tr>
+ </tfoot>
+ <tbody>
+ {% for item in group %}
+ <tr>
+ <td class="col-sm-4">{{ item.product }}{% if item.quantity != 1 %} <em>×{{ item.quantity }}</em>{% endif %}</td>
+ <td class="col-sm-2">{% gross item.get_price_per_item %}</td>
+ <td class="col-sm-2">{% gross item.get_total %}</td>
+ </tr>
+ {% endfor %}
+ {% if group.get_delivery_total.gross %}
+ <tr>
+ <td class="col-sm-4">
+ {% trans "Shipping" %} ({{ group.get_delivery_method }})
+ </td>
+ <td class="col-sm-2">{% gross group.get_delivery_total %}</td>
+ <td class="col-sm-2">{% gross group.get_delivery_total %}</td>
+ </tr>
{% endif %}
- </tr>
- {% endfor %}
- {% endfor %}
- </tbody>
- </table>
- <form method="post">
- {% csrf_token %}
- <button type="submit" class="btn btn-primary">
- {% trans "Place order" %}
- </button>
- </form>
+ </tbody>
+ </table>
+ {% if group.email %}
+ <p>{% trans "Will be sent to" %} {{ group.email }}</p>
+ {% elif group.address %}
+ <p>{% trans "Will be shipped to" %} {% include "userprofile/snippets/address-short.html" with address=group.address %}</p>
+ {% else %}
+ <p class="text-danger">{% trans "No address given yet." %}</p>
+ {% endif %}
+ <p><a href="{{ group.step.get_absolute_url }}">{% trans "Edit delivery details" %}</a></p>
+ </div>
+ </div>
+ {% endfor %}
+
+ {% with total=checkout.get_total %}
+ <p>
+ {% trans "Order total" %}:
+ <strong>{% gross checkout.get_total %}</strong>
+ {% if total.gross %}
+ ({% blocktrans with tax=total.tax|floatformat:2 currency=total.currency %}includes {{ tax }} <span class="currency">{{ currency }}</span> tax{% endblocktrans %})
+ {% endif %}
+ </p>
+ {% endwith %}
+
+ {% if all_steps_valid %}
+ <form method="post">
+ {% csrf_token %}
+ <button type="submit" class="btn btn-primary">
+ {% trans "Place order" %}
+ </button>
+ </form>
+ {% else %}
+ <div class="alert alert-danger">
+ <p>{% trans "Before continuing please make sure that you've provided all of the information required." %}</p>
+ </div>
+ {% endif %}
{% endblock forms %}
{% block footer_scripts %}