Skip to content

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

Add confirmation emails sending in order & payment

Michal Ociepkaca35d64e919f
diff --git a/order/models.py b/order/models.py
index 40750ea7fb..ea61c78fa4 100644
--- a/order/models.py
+++ b/order/models.py
@@ -1,10 +1,13 @@
+from communication.mail import send_email
from decimal import Decimal
from django.conf import settings
+from django.core.urlresolvers import reverse
from django.db import models
from django.utils.translation import pgettext_lazy
from django_prices.models import PriceField
from prices import Price
from product.models import Product, Subtyped
+from saleor.utils import build_absolute_uri
from satchless.item import ItemSet, ItemLine
from userprofile.models import Address
from uuid import uuid4
@@ -78,14 +81,20 @@ class Order(models.Model, ItemSet):
def billing_full_name(self):
return u'%s %s' % (self.billing_first_name, self.billing_last_name)
- @models.permalink
def get_absolute_url(self):
- return ('order:details', (), {'token': self.token})
+ return reverse('order:details', kwargs={'token': self.token})
def get_delivery_total(self):
return sum([group.price for group in self.groups.all()],
Price(0, currency=settings.SATCHLESS_DEFAULT_CURRENCY))
+ def send_confirmation_email(self):
+ email = self.get_user_email()
+ payment_url = build_absolute_uri(
+ reverse('order:payment:index', kwargs={'token': self.token}))
+ context = {'payment_url': payment_url}
+ send_email(email, 'order/emails/confirm_email.txt', context)
+
class DeliveryGroup(Subtyped, ItemSet):
diff --git a/payment/models.py b/payment/models.py
index 660f39330b..9c47e46f33 100644
--- a/payment/models.py
+++ b/payment/models.py
@@ -1,7 +1,9 @@
+from communication.mail import send_email
from django.core.urlresolvers import reverse
from django.db import models
from order.models import Order
from payments.models import BasePayment
+from saleor.utils import build_absolute_uri
class Payment(BasePayment):
@@ -14,3 +16,10 @@ class Payment(BasePayment):
def get_success_url(self):
return reverse('order:success', kwargs={'token': self.order.token})
+
+ def send_confirmation_email(self):
+ email = self.order.get_user_email()
+ order_url = build_absolute_uri(
+ reverse('order:details', kwargs={'token': self.order.token}))
+ context = {'order_url': order_url}
+ send_email(email, 'payment/emails/confirm_email.txt', context)