Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add HTML template for order confirmation e-mail
Anna Siwik363126a47cba
diff --git a/saleor/order/emails.py b/saleor/order/emails.pyindex fc4ba8978a..5d9a2cd24e 100644--- a/saleor/order/emails.py+++ b/saleor/order/emails.py@@ -8,19 +8,22 @@ CONFIRM_PAYMENT_TEMPLATE = 'order/payment/confirm_payment'CONFIRM_NOTE_TEMPLATE = 'order/note/confirm_note'-def _send_confirmation(email, url, template):+def _send_confirmation(email, url, template, ctx=None):site = Site.objects.get_current()+ context = {'site_name': site.name, 'url': url}+ if ctx:+ context.update(ctx)send_templated_mail(from_email=settings.ORDER_FROM_EMAIL,recipient_list=[email],- context={'site_name': site.name,- 'url': url},+ context=context,template_name=template)@shared_task-def send_order_confirmation(email, url):- _send_confirmation(email, url, CONFIRM_ORDER_TEMPLATE)+def send_order_confirmation(email, url, order):+ ctx = {'order': order}+ _send_confirmation(email, url, CONFIRM_ORDER_TEMPLATE, ctx)@shared_taskdiff --git a/saleor/order/models.py b/saleor/order/models.pyindex 2f261a0a75..baec54976c 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -131,7 +131,7 @@ class Order(models.Model, ItemSet):email = self.get_user_current_email()payment_url = build_absolute_uri(reverse('order:details', kwargs={'token': self.token}))- emails.send_order_confirmation.delay(email, payment_url)+ emails.send_order_confirmation.delay(email, payment_url, self)def get_last_payment_status(self):last_payment = self.payments.last()diff --git a/saleor/static/emails/scss/components/_tables.scss b/saleor/static/emails/scss/components/_tables.scssindex e0809e7c62..d0376f75d7 100644--- a/saleor/static/emails/scss/components/_tables.scss+++ b/saleor/static/emails/scss/components/_tables.scss@@ -7,7 +7,18 @@ body {margin: auto;}- header .logo {- fill: black;+ header {+ padding: 0.75em;+ background-color: $light-gray;+ }++ .right-align {+ text-align: right;+ }++ footer {+ text-align: center;+ padding: 0.75em;+ background-color: $gray;}}diff --git a/saleor/static/emails/scss/variables.scss b/saleor/static/emails/scss/variables.scssindex 1eec7fcd16..84691da2f4 100644--- a/saleor/static/emails/scss/variables.scss+++ b/saleor/static/emails/scss/variables.scss@@ -1 +1,5 @@$font-family-sans-serif: 'Lato', sans-serif;++// COLORS+$light-gray: #f2f2f2;+$gray: #D3D1D0;diff --git a/templates/templated_email/html/base.html b/templates/templated_email/html/base.htmlindex beedac4f87..39c0c623bc 100644--- a/templates/templated_email/html/base.html+++ b/templates/templated_email/html/base.html@@ -15,6 +15,9 @@<td><footer>{% block footer %}+ {% blocktrans trimmed context "Base e-mail footer" %}+ Sincerely, {{ site_name }}+ {% endblocktrans %}{% endblock footer %}</footer></td>@@ -25,7 +28,7 @@<td><header>{% block header %}- <img class="logo" src='{% static 'images/logo.png' %}' alt="{% trans "Saleor" %}" width="200" />+ <svg data-src="{% static "images/logo.svg" %}" height="38px" width="176px"/>{% endblock header %}</header></td>diff --git a/templates/templated_email/html/order/confirm_order.html b/templates/templated_email/html/order/confirm_order.htmlnew file mode 100644index 0000000000..97e23e0e19--- /dev/null+++ b/templates/templated_email/html/order/confirm_order.html@@ -0,0 +1,40 @@+{% extends "templated_email/html/base.html" %}+{% load i18n_address_tags %}+{% load i18n %}++{% block content %}+<table>+ <tbody>+ <tr>+ <td colspan="2" class="email-text table-content">+ {% blocktrans context "Order confirmation email text" %}+ <p>Hi!</p>+ <p>Thank you for your order. Below is the list of ordered products. To see your payment details please visit: <a href="{{ url }}">{{ url }}</a></p>+ {% endblocktrans %}+ </td>+ </tr>+ <tr>+ <td colspan="2">+ {% include 'templated_email/html/order/partials/_order_lines.html' with order=order %}+ </td>+ </tr>+ <tr>+ <td>+ {% trans "Billing address" context "Order confirmation e-mail billing address" %}+ <br>{{ order.billing_address }}+ </td>+ <td>+ {% trans "Shipping address" context "Order confirmation e-mail shipping address" %}+ <br>{{ order.shipping_address }}+ </td>+ </tr>+ <tr>+ <td colspan="2">+ {% blocktrans context "Order confirmation email text" %}+ <p>This is an automatically generated e-mail, please do not reply.</p>+ {% endblocktrans %}+ </td>+ </tr>+ </tbody>+</table>+{% endblock content %}diff --git a/templates/templated_email/html/order/partials/_order_lines.html b/templates/templated_email/html/order/partials/_order_lines.htmlnew file mode 100644index 0000000000..59a3d0d845--- /dev/null+++ b/templates/templated_email/html/order/partials/_order_lines.html@@ -0,0 +1,40 @@+{% load gross from prices_i18n %}++<table class="center-table">+ <tfoot>+ <tr>+ <td colspan="3" class="right-align">+ <p class="right-align">Subtotal</p>+ <p class="right-align">Shipping</p>+ <p class="right-align"><strong>Total</strong></p>+ </td>+ <td class="table-summary right-align">+ <p class="right-align">{% gross order.get_total html=True %}</p>+ <p class="right-align">{% gross order.shipping_price html=True %}</p>+ <p class="right-align"><strong>{% gross order.get_total html=True %}</strong></p>+ </td>+ </tr>+ </tfoot>+ <thead>+ <tr>+ <th class="table-title">Item</th>+ <th class="table-title">Quantity</th>+ <th class="table-title">Per unit</th>+ <th class="table-title">Subtotal</th>+ </tr>+ </thead>+ <tbody>+ {% for group in order.groups.all %}+ {% for line in group.lines.all %}+ <tr class="{% if forloop.last %}last-item-row{% endif %}">+ <td class="table-list-item">{{ line.product_name }}</td>+ <td class="table-list-item right-align">{{ line.quantity }}</td>+ <td class="table-list-item right-align">+ {% gross line.get_price_per_item html=True %}+ </td>+ <td class="table-list-item right-align">{% gross line.get_total %}</td>+ </tr>+ {% endfor %}+ {% endfor %}+ </tbody>+</table>diff --git a/templates/templated_email/order/confirm_order.email b/templates/templated_email/order/confirm_order.emailindex ea7b55da97..4e701bd224 100644--- a/templates/templated_email/order/confirm_order.email+++ b/templates/templated_email/order/confirm_order.email@@ -17,3 +17,7 @@ Sincerely,{{ site_name }}{% endblocktrans %}{% endblock %}++{% block html %}+{% include 'templated_email/html/order/confirm_order.html' %}+{% endblock %}