Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Warren Harding 116 posts 256 karma points
    Jul 01, 2022 @ 08:05
    Warren Harding
    0

    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

  • Matt Brailsford 3688 posts 19399 karma points MVP 9x c-trib
    Jul 01, 2022 @ 08:37
    Matt Brailsford
    0

    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 the IEmailTemplateService to retrieve your email template and call the services SendEmail method to trigger sending it.

    Hope this helps

    Matt

  • Warren Harding 116 posts 256 karma points
    Jul 01, 2022 @ 08:41
    Warren Harding
    0

    Thank you Matt, unfortunately this build is still on Umbraco 8 - and using Vendr 1.8, does this still apply?

  • Matt Brailsford 3688 posts 19399 karma points MVP 9x c-trib
    Jul 01, 2022 @ 08:51
    Matt Brailsford
    0

    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

  • Warren Harding 116 posts 256 karma points
    Jul 01, 2022 @ 09:55
    Warren Harding
    0

    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.
            }
        }
    }
    
  • Matt Brailsford 3688 posts 19399 karma points MVP 9x c-trib
    Jul 01, 2022 @ 10:10
    Matt Brailsford
    100

    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

  • Warren Harding 116 posts 256 karma points
    Jul 04, 2022 @ 04:40
    Warren Harding
    0

    Brilliant thanks for that

Please Sign in or register to post replies

Write your reply to:

Draft