Skip to content

Commit

Permalink
#671 phone in order mail (#672)
Browse files Browse the repository at this point in the history
* Create test case to catch an issue.

* Fix issues with render_to_string function.
  • Loading branch information
ArtemijRodionov authored and duker33 committed Dec 18, 2018
1 parent be3bca7 commit 1d05540
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions shopelectro/tests/tests_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,9 @@ def test_order_email(self):
self.assertIn('Наличные', sent_mail_body)
self.assertIn('+7 (222) 222 22 22', sent_mail_body)
self.assertIn('test@test.test', sent_mail_body)
self.assertIn(f'tel:{settings.SHOP["cps_phone"]}', sent_mail_body)
self.assertIn(settings.SHOP['cps_formatted_phone'], sent_mail_body)

for code in clean_codes:
self.assertInHTML(
'<td align="left"'
Expand Down
10 changes: 8 additions & 2 deletions shopelectro/views/ecommerce.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
class OrderPage(ec_views.OrderPage):
order_form = OrderForm
cart = SECart
# Django does not provide context_processors for render_to_string function,
# which is used to render an order mail. So we have to explicitly pass
# a context to it.
email_extra_context = {'shop': settings.SHOP}

def get_context_data(self, request, **kwargs):
data = super().get_context_data(request, **kwargs)
Expand Down Expand Up @@ -79,9 +83,9 @@ def one_click_buy(request):
Accept XHR, save Order to DB, send mail about it
and return 200 OK.
"""
SECart(request.session).clear()

cart = SECart(request.session)
cart.clear()

product = get_object_or_404(Product, id=request.POST['product'])
cart.add(product, int(request.POST['quantity']))
order = Order(phone=request.POST['phone'])
Expand All @@ -91,6 +95,8 @@ def one_click_buy(request):
subject=settings.EMAIL_SUBJECTS['one_click'],
order=order,
to_customer=False,
# see se.OrderPage class for a detail about `shop` context.
extra_context={'shop': settings.SHOP},
)
return HttpResponse('ok')

Expand Down
4 changes: 4 additions & 0 deletions shopelectro/views/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ def send_mail_to_shop(order):
'paid': paid,
'profit': profit,
'commission': commission,
# see se.OrderPage class for a detail about `shop` context.
'shop': settings.SHOP,
})

def send_mail_to_customer(order):
mailer.send_order(
subject=settings.EMAIL_SUBJECTS['yandex_order'],
order=order,
to_shop=False,
# see se.OrderPage class for a detail about `shop` context.
extra_context={'shop': settings.SHOP},
)

if not has_correct_md5(request.POST):
Expand Down

0 comments on commit 1d05540

Please sign in to comment.