问题描述
我想收到通知
当我的django-oscar商店有新订单时,
对我自己(作为管理员).
to myself (As Admin) when there is new order placed on my django-oscar store.
推荐答案
我遵循的一种方式是向管理员发送电子邮件,我所做的是将订单应用程序分叉并转到utils.py,到OrderCreator()类下的place_order函数,oscar发送信号以进行订单放置,来自oscar的github的代码是此处,所以我所做的就是在此之后添加了发送电子邮件代码.因此,我在管理员端创建了一个代码为ADMIN_ORDER_MAIL的通信事件类型,并在此处用于发送邮件.
There is a way that I am following to send emails to the admins, what I did was forked the order app and the went to the utils.py, went to the place_order function under OrderCreator() class, oscar sends signals for order placement the code from oscar's github is here, so what I did was put my send email code after this.SO I created a communication event type with code ADMIN_ORDER_MAIL in my admin side and used that here to send mails.
我的代码在这里:
# Send an email to admin on placing of order
ctx = {'order': order, 'user': order.user}
commtype_code = 'ADMIN_ORDER_MAIL'
try:
event_type = CommunicationEventType.objects.get(code=commtype_code)
# print("Event type typr: ", type(event_type))
# self.create_communication_event(order, event_type)
except Exception as e:
messages = CommunicationEventType.objects.get_and_render(code=commtype_code, context=ctx)
# print(e)
else:
messages = event_type.get_messages(ctx)
send_mail(
subject=messages['subject'],
message='',
html_message=messages['html'],
from_email='from email address',
recipient_list=['to email address'],
fail_silently=False,
)
这篇关于django oscar:如何向商店管理员发送电子邮件以进行订单放置通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!