Sending a different confirmation email to the admin
Hi there, could you please advise how to send a second "Order Confirmation" email to an administrator?
I've created a second template and duplicated orderConfirmation as a base (new one is adminOrderConfirmation) - with the only change being the subject line at this stage, yet only orderConfirmation is being sent/received.
Is there something I've missed with this process above, or will I need to implement a pipeline to handle this? And if so, how would I go about picking up a different template file?
We currently only have the ability to automatically send one confirmation email, but you can hook into Vendr's event system to trigger sending your own email.
You should be able to register an event for the OrderFinalizedNotification notification (See docs here for registering event handlers https://vendr.net/docs/core/2.1.0/umbraco-v9/key-concepts/events/) and then use the IEmailTemplateService to retrieve your email template and call the services SendEmail method to trigger sending it.
Brilliant, ok so far I have the following - is this correct so far, and how do I do these next bits? Thank you
public class MyOrderFinalizedComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.WithNotificationEvent<OrderFinalizedNotification>()
.RegisterHandler<MyOrderFinalizedHandler>();
composition.Logger.Warn<MyOrderFinalizedComposer>("MyOrderFinalizedComposer...");
}
}
public class MyOrderFinalizedHandler : NotificationEventHandlerBase<OrderFinalizedNotification>
{
public override void Handle(OrderFinalizedNotification evt)
{
var orderLine = evt.Order.OrderLines?.First(x => x.Properties != null && x.Properties["formEntry"] != null);
if (orderLine != null)
{
// use the IEmailTemplateService to retrieve your email template
// call the services SendEmail method to trigger sending it.
}
}
}
For the last bits you'll want to use dependency injection to inject the IEmailTemplateService into your notification handler, then store it in a private variable to be accessed within your handler.
Where you have the code comment, you'll then want to access that service instance to fetch your template (by alias would be easiest) and then call SendEmail on the service to trigger sending it.
Hi matt,
is it possible to override the default email sender with a custom one?
My need is to send two different email templates depending on the type of object sold.
I guess I could handle the logic directly in the template, but the template would quickly become a mess.
Sending a different confirmation email to the admin
Hi there, could you please advise how to send a second "Order Confirmation" email to an administrator?
I've created a second template and duplicated orderConfirmation as a base (new one is adminOrderConfirmation) - with the only change being the subject line at this stage, yet only orderConfirmation is being sent/received.
Is there something I've missed with this process above, or will I need to implement a pipeline to handle this? And if so, how would I go about picking up a different template file?
Thanks again, Warren
Hi Warren
We currently only have the ability to automatically send one confirmation email, but you can hook into Vendr's event system to trigger sending your own email.
You should be able to register an event for the
OrderFinalizedNotification
notification (See docs here for registering event handlers https://vendr.net/docs/core/2.1.0/umbraco-v9/key-concepts/events/) and then use theIEmailTemplateService
to retrieve your email template and call the servicesSendEmail
method to trigger sending it.Hope this helps
Matt
Thank you Matt, unfortunately this build is still on Umbraco 8 - and using Vendr 1.8, does this still apply?
Hey Warren,
It does yea, just switch the docs to the v8 version https://vendr.net/docs/core/2.1.0/umbraco-v8/key-concepts/events/
Hope this helps
Matt
Brilliant, ok so far I have the following - is this correct so far, and how do I do these next bits? Thank you
Hey Warren,
Yup looks good so far.
For the last bits you'll want to use dependency injection to inject the
IEmailTemplateService
into your notification handler, then store it in a private variable to be accessed within your handler.Where you have the code comment, you'll then want to access that service instance to fetch your template (by alias would be easiest) and then call
SendEmail
on the service to trigger sending it.There are some docs here on dependency injection https://vendr.net/docs/core/2.1.0/umbraco-v8/key-concepts/dependency-injection/
Hope this helps
Matt
Brilliant thanks for that
Hi matt, is it possible to override the default email sender with a custom one? My need is to send two different email templates depending on the type of object sold. I guess I could handle the logic directly in the template, but the template would quickly become a mess.
Thanks, alessandro
is working on a reply...