问题
I want to get a notification
to myself (As Admin) when there is new order placed on my django-oscar store.
回答1:
I think that you can use django signals.
Django-Oscar has some signals defined for multiple actions, and one of them is associated to the action of order placed.
This signal provide information about the order made and the user who made the order. You can use this information to send the email.
I hope it will be useful for you!
回答2:
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.
My code is here:
# 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,
)
来源:https://stackoverflow.com/questions/37089210/django-oscar-how-to-send-an-email-to-store-admin-for-order-placement-notificati