Copied to clipboard

Flag this post as spam?

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


  • Hutch White 89 posts 112 karma points
    Aug 14, 2012 @ 02:37
    Hutch White
    0

    Order Emails

    Hi,

    I'm looking for some clarification/guidance for order emails.  I'm trying to implement an admin only email to be sent as confirmation that would contain different email info than is sent to the customer.  I've determined that the tasks should be:

    1. Create XSLT mail template for Admin email
    2. Create additional Confirmation Email node in TeaCommerce Admin Section\Confirmation Emails.
    3. Create interface to attach to AfterOrderConfirmationMailSend
    My questions are:
    • For item 2 above, how will Tea Commerce know which email to send to the customer?  Will it send both if I add one here?
    • For item 3 above, how can I grab the node associated to this created from item 2 and the associated XSLT to format the email?
    • Is there a function for sending email somewhere in the API to basically send the confirmation email again with different parameters (ie, to, from, subject, body)?

  • Rune Grønkjær 1372 posts 3103 karma points
    Aug 14, 2012 @ 08:20
    Rune Grønkjær
    0

    Hi Hutch,

    What you want to do is pretty straight forward. When you know how to do it, of cause :)

    First of all, to explain the email template system in Tea Commerce:
    - Only the email selected in "general settings > Confirmation E-mail" will be sent automatically when an order is finalized.
    - As standard, all Tea Commerce e-mails will be sent to the customer AND to any email specified on the e-mail in the Tea Commerce section
    - When any Tea Commerce e-mail is sent the BeforeMailSend and then the AfterMailSend events are fired
    - If the mail is the default confirmation mail the BeforeOrderConfirmationMailSend and AfterOrderConfirmationMailSend will be fired as well

    Your task will be this:
    - Create another e-mail in the Tea Commerce section. Just as you have written above.
    - Hook into the AfterOrderFinalized event (Which is more correct than the AfterOrderConfirmationMailSend, as it is sure to happen when an order is placed). There you will get your new e-mail template with the static EmailTemplate.GetEmailTemplate() method. Now just Send() the e-mail
    - Hook into the BeforeMailSend event, and check the alias of the email. If it's your new e-mail template remove the "To" reciever, which is the customer.

    That's it. Hope it works for you.

    /Rune

  • Hutch White 89 posts 112 karma points
    Aug 14, 2012 @ 19:20
    Hutch White
    0

    Thanks for the response!  With that I was able to very quickly complete what I was looking to do.  :)

    For anyone interested, here's the code (be sure to follow the above).  If anyone has questions on this feel free to ask!

     

    using System;

     

    using System.Collections.Generic;

    using System.Configuration;

    using System.IO;

    using System.Linq;

    using System.Net.Mail;

    using System.Net.Mime;

    using System.Text;

    using System.Web;

    using System.Xml;

    using System.Xml.XPath;

    using TeaCommerce.Data;

    using TeaCommerce.Data.Extensibility;

    using TeaCommerce.Data.Tools;

    using TeaCommerce.WebShop.Integration;

    using umbraco.BusinessLogic;

     

    namespace TeaCommerce.WebShop.Integration

    {

        public class LicenseExtension : ITeaCommerceExtension

        {

            #region ITeaCommerceExtension Members

     

            string _strEmailAlias = ConfigurationManager.AppSettings["AdminOrderEmailAlias"].ToString();

     

            public void Initialize()

            {

                WebshopEvents.AfterOrderFinalized += OrderController_AfterOrderFinalized;

                WebshopEvents.BeforeMailSend += OrderController_BeforeMailSend;

            }

     

            #endregion

     

            void OrderController_AfterOrderFinalized(Order order, Data.Payment.CallbackInfo pci)

            {

                EmailTemplate.GetEmailTemplate(_strEmailAlias).Send(order);

                WebshopEvents.BeforeMailSend += OrderController_BeforeMailSend;

            }

     

            void OrderController_BeforeMailSend(Order order, MailMessage mail, EmailTemplate emailTemplate)

            {

                string strEmailTo = ConfigurationManager.AppSettings["AdminOrderEmailTo"].ToString();

     

                if (emailTemplate.Alias == _strEmailAlias)

                {

                    mail.To.Clear();

                    mail.To.Add(new MailAddress(strEmailTo));

                }

            }

        }

    }

     

Please Sign in or register to post replies

Write your reply to:

Draft