Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTML support for mail notification #50

Merged
merged 27 commits into from
Oct 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b7d3aab
multiplart mail notify WIP
rnixx Oct 6, 2017
c16c715
document signature change
rnixx Oct 6, 2017
9d0abac
Add basic EN html mail notification templates
rnixx Oct 6, 2017
51f94b9
Add en HTML mail notification templates to template registry
rnixx Oct 6, 2017
25f3b96
Add mail_listing_item utility function
rnixx Oct 20, 2017
d0109d1
item mail listing creation WIP
rnixx Oct 20, 2017
dd8a3b6
item mail listing creation WIP
rnixx Oct 20, 2017
7a221a5
Add order_summary_data function
rnixx Oct 21, 2017
08ead2b
More data extraction separation from text generation
rnixx Oct 21, 2017
39ead4b
Some fixes
rnixx Oct 21, 2017
fb09d56
Move delivery address generation to template callback
rnixx Oct 21, 2017
24bf505
Listing items data extraction in dedicated function, basic pt
rnixx Oct 21, 2017
6b572f3
Some cleanup
rnixx Oct 21, 2017
557aa2c
Signature of create_text_mail_body, create_html_mail_body, do_notify,…
rnixx Oct 21, 2017
9827284
HTML template related data
rnixx Oct 21, 2017
b1b2b58
HTML templates WIP
rnixx Oct 21, 2017
8df898c
Order success html mail WIP
rnixx Oct 22, 2017
f025695
Order success html mail WIP
rnixx Oct 22, 2017
2c00c5a
Order success html mail WIP
rnixx Oct 22, 2017
ab51cbf
Cancel booking fixes, improvements and HTML mail
rnixx Oct 22, 2017
c1a5659
Booking reserved to ordered HTML notification mail
rnixx Oct 22, 2017
1a4718d
Stock threshold reached HTML notification mail
rnixx Oct 22, 2017
d8c3f7e
Some order sucess html template fixes
rnixx Oct 22, 2017
a9e0719
German translations for order related HTML mails
rnixx Oct 22, 2017
99dc1f5
Remove non related code to this branch
rnixx Oct 22, 2017
b1c4339
Some polishing, update docs
rnixx Oct 22, 2017
eef1ed5
Update TODO
rnixx Oct 22, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ Changelog
1.0a1 (unreleased)
------------------

- Add HTML support for order related notification mails.
[rnix]

- Change signature of ``bda.plone.orders.MailNotify.send``. Accepts now
``subject``, ``receiver`` and ``text`` as positional arguments and an
optional ``html`` argument.
[rnix]

- Also handle transaction id and payment state for ``bda.plone.stripe``
payment in ``bda.plone.common.payment_success`` and
``bda.plone.common.payment_failed`` event subscribers.
Expand Down
43 changes: 43 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,41 @@ After that you can start customizing the order process:
Mail notifications
------------------

Order related notification is done by sending multipart mails containing a
text and a HTML version of the notification payload.

When customizing mail notification, both text and HTML templates needs to be
customized.

.. warning::

As of ``bda.plone.orders`` 1.0a1, signatue of
``bda.plone.orders.MailNotify.send`` changed. It accepts now
``subject``, ``receiver`` and ``text`` as positional arguments and an
optional ``html`` argument.


HTML Templates
~~~~~~~~~~~~~~

Default HTML templates are located at ``bda.plone.orders:mailtemplates``.
To customize them, copy the entire template folder to your integration package
and patch ``bda.plone.orders.mailnotify.MAIL_TEMPLATES_DIRECTORY`` like so:

.. code-block:: python

from bda.plone.orders import mailnotify
import os

mailnotify.MAIL_TEMPLATES_DIRECTORY = os.path.join(
os.path.dirname(__file__),
'mailtemplates'
)


Text Templates
~~~~~~~~~~~~~~

Copy the messages you need to customize from
``bda.plone.orders.mailtemplates`` and change the text to your needs.
There are two dictionaries containing all the strings, ``ORDER_TEMPLATES``
Expand All @@ -67,6 +102,10 @@ in sync with the original templates and check if all stock variables
(such as ``global_text`` or the ``@@showorder`` link which have been
added in version 0.4 are present.)


Customize notification mechanism
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Alternativly you add/replace the notification methods and implement your
own very custom. To do provide your own two functions similar to
``bda.plone.orders.mailnotify.notify_checkout_success`` and
Expand Down Expand Up @@ -240,6 +279,10 @@ Create translations
TODO
====

- Adopt text notification mail generation to mako templates and move existing
text mail generation to legacy module, with flag to switch between old and
new style text generation.

- @@orders in lineage subsites should only list orders in that path.

- Consider vendor UID's and booking based state in mail notification
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
'bda.plone.cart',
'bda.plone.checkout',
'bda.plone.discount',
'Chameleon',
'collective.js.datatables',
'collective.js.jqueryui',
'plone.api',
Expand Down
2 changes: 1 addition & 1 deletion src/bda/plone/orders/browser/notify_customers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _sendmail(self, notifier, uid, tpl, subject):
if key in order.attrs:
data[key] = order.attrs[key]
body = TEMPLATE(tpl, data).encode('utf-8')
notifier.send(subject, body, order.attrs['personal_data.email'])
notifier.send(subject, order.attrs['personal_data.email'], body)

def send(self, widget, data):
tpl = data['text'].extracted.decode('utf8')
Expand Down
33 changes: 18 additions & 15 deletions src/bda/plone/orders/browser/order.pt
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,17 @@
show_exported python:'exported' in row">

<tr tal:condition="start">
<th i18n:translate="booking_title">title</th>
<th i18n:translate="booking_count">count</th>
<th i18n:translate="booking_quantity_unit">quantity unit</th>
<th i18n:translate="booking_currency">currency</th>
<th i18n:translate="booking_net">net</th>
<th i18n:translate="booking_discount_net">discount net</th>
<th i18n:translate="booking_vat">vat</th>
<th tal:condition="show_exported" i18n:translate="booking_exported">exported</th>
<th i18n:translate="booking_comment">comment</th>
<th i18n:translate="booking_state">state</th>
<th i18n:translate="booking_salaried">salaried</th>
<th i18n:translate="booking_title">Title</th>
<th i18n:translate="booking_count">Count</th>
<th i18n:translate="booking_quantity_unit">Quantity</th>
<th i18n:translate="booking_currency">Currency</th>
<th i18n:translate="booking_net">Net</th>
<th i18n:translate="booking_discount_net">Discount net</th>
<th i18n:translate="booking_vat">Vat</th>
<th tal:condition="show_exported" i18n:translate="booking_exported">Exported</th>
<th i18n:translate="booking_comment">Comment</th>
<th i18n:translate="booking_state">State</th>
<th i18n:translate="booking_salaried">Salaried</th>
</tr>

<tr tal:attributes="class python:even and 'even' or 'odd'">
Expand Down Expand Up @@ -235,11 +235,14 @@
</td>
<td>
<span tal:content="row/state">state</span>
<a tal:condition="python:view.can_cancel_booking"
tal:attributes="href string:${context/absolute_url}/@@booking_cancel?uid=${row/uid}"
i18n:translate="booking_cancel"
<a tal:condition="row/cancel_url"
tal:attributes="href row/cancel_url"
class="booking-cancel-link discreet"
href="#"><img src="#" title="cancel booking" alt="cancel booking icon" tal:attributes="src string:${context/absolute_url}/++resource++bda.plone.orders/delete.png"/></a>
href="#"><img
src="#"
title="cancel booking"
alt="cancel booking"
tal:attributes="src string:${context/absolute_url}/++resource++bda.plone.orders/delete.png" /></a>
</td>
<td tal:content="row/salaried">salaried</td>
</tr>
Expand Down
20 changes: 10 additions & 10 deletions src/bda/plone/orders/browser/resources/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@
},

cancel_confirm_binder: function(context) {
$('.booking-cancel-link')
.unbind('click')
.bind('click', orders.cancel_confirm);
},

cancel_confirm: function(event) {
var result = window.confirm('Are you sure?');
if (!result) {
event.preventDefault();
}
$('.booking-cancel-link', context).bind('click', function(evt) {
evt.preventDefault();
var options = {
message: 'Are you sure?',
url: $(this).attr('href')
};
bdajax.dialog(options, function(options) {
window.location.href = options.url;
});
});
},

comment_edit_binder: function(event) {
Expand Down
8 changes: 8 additions & 0 deletions src/bda/plone/orders/browser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from bda.plone.orders.transitions import transitions_of_main_state
from bda.plone.orders.transitions import transitions_of_salaried_state
from plone.memoize import view
from plone.protect.utils import addTokenToUrl
from repoze.catalog.query import Any
from repoze.catalog.query import Contains
from repoze.catalog.query import Eq
Expand Down Expand Up @@ -750,15 +751,22 @@ def currency(self):
@property
def listing(self):
# XXX: discount
can_cancel_booking = self.can_cancel_booking
ret = list()
for booking in self.order_data.bookings:
obj = get_object_by_uid(self.context, booking.attrs['buyable_uid'])
state = vocabs.state_vocab()[booking.attrs.get('state')]
salaried = vocabs.salaried_vocab()[booking.attrs.get('salaried')]
cancel_url = None
if can_cancel_booking:
cancel_url = addTokenToUrl('{}/@@booking_cancel?uid={}'.format(
self.context.absolute_url(),
booking.attrs['uid']))
ret.append({
'uid': booking.attrs['uid'],
'title': booking.attrs['title'],
'url': obj.absolute_url(),
'cancel_url': cancel_url,
'count': booking.attrs['buyable_count'],
'net': ascur(booking.attrs.get('net', 0.0)),
'discount_net': ascur(float(booking.attrs['discount_net'])),
Expand Down
Loading