Is it possible to send and order confirmation email when creating an order using the API and not though "Shopping Cart" module?
If yes, please give examples.
Developer forum
E-mail notifications
Send order confirmation from API
Martin Grønbekk Moen
Posted on 13/09/2019 15:17:23
Replies
Morten Snedker
Posted on 16/09/2019 15:17:21
Hi Martin,
You can use one of the many notification subsribers on the cart to hook up on the order and retreive the information necessary, and pass it on in a mail by using the System.Net.Mail namespace. In the example below it is the CheckoutDoneOrderIsComplete notification that is used. The example is raw data - you'd need to apply the formatting (like html) yourself if required.
using Dynamicweb.Ecommerce.Notifications; using Dynamicweb.Extensibility.Notifications; namespace Ecom { [Subscribe(Ecommerce.Cart.CheckoutDoneOrderIsComplete)] public class CheckoutDoneOrderIsComplete1 : NotificationSubscriber { public override void OnNotify(string notification, NotificationArgs args) { Ecommerce.Cart.CheckoutDoneOrderIsCompleteArgs orderArgs = args as Ecommerce.Cart.CheckoutDoneOrderIsCompleteArgs; string mailEmail = orderArgs.Order.CustomerEmail; string mailName = orderArgs.Order.CustomerName; string orderlines = string.Empty; foreach (var ol in orderArgs.Order.OrderLines) { orderlines += $"{ol.ProductName} | {ol.Quantity} | {ol.Price.PriceFormatted}<br>"; } SendMail(mailEmail, mailName, orderlines); } private void SendMail(string MailAddress, string MailName, string MailBody) { // Mail stuff } } }
Best regards
Snedker
Nicolai Pedersen
Posted on 16/09/2019 15:20:02
Remember to never use httpcontext in this piece of code, as there is none when it is a callback from a payment gateway.
You must be logged in to post in the forum