Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Print Receipt from an order View modes: 
User avatar
Member
Member
knottano-gmail - 5/2/2012 9:40:33 PM
   
Print Receipt from an order
Hi,

I have a question about email templates (Site Mgr > Administration > Email templates)

In Kentico 6.0, once the order has saved and the customer payment succeed, it will send out the "Order payment notification to customer" (Code name: Ecommerce.OrderPaymentNotificationToCustomer)

Is there a way to programmatically send it again in the code?

What I mean in detail is: I would like to retrieve an order (by orderId) which I know I can use "OrderInfoProvider.GetOrderInfo(orderId)" and after I get the OrderInfo object. I would like to send the email of the same template (Code name: Ecommerce.OrderPaymentNotificationToCustomer") to the customer.

Please help,
Thank you

User avatar
Member
Member
kentico_michal - 5/6/2012 4:43:47 AM
   
RE:Print Receipt from an order
Hi,

To send the notification email to the customer, you can use the following method:

OrderInfoProvider.SendOrderNotificationToCustomer(ShoppingCartInfo cartInfo)

As you can see, it requires a valid ShoppingCartInfo object that you can retrieve with this method:

ShoppingCartInfo cartInfo = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(orderID);

Best regards,
Michal Legen

User avatar
Member
Member
knottano-gmail - 5/6/2012 7:44:12 AM
   
RE:Print Receipt from an order
Hi Michael,

Could you please help me more with this?

How to show that email template with the order data on the website instead of sending it?

After a customer paid for the order, normally they will receive the email (the one I mentioned above). But instead of sending it, how to show the email on the "Thank you page" with all the order information bind to variables in the template.

Thank you very much,
Knott

User avatar
Member
Member
kentico_michal - 5/6/2012 8:09:55 AM
   
RE:Print Receipt from an order
Hi,

First you need to get the shopping cart object based on the OrderID and the template you are about to display. Once you have done so, you can get the template text and create a MacroResolver using the OrderInfoProvider.CreateEmailMacroResolver method. Then, you can simply resolve all macros in the template text. Please take a look at the following code:


ShoppingCartInfo cartObj = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(OrderID);

// Get email template
EmailTemplateInfo template = EmailTemplateProvider.GetEmailTemplate("Ecommerce.OrderPaymentNotificationToCustomer", cartObj.SiteName);

// Check template presence
if (template == null)
{
return;
}

string body = URLHelper.MakeLinksAbsolute(template.TemplateText);

// Prepare the macro resolver
MacroResolver resolver = OrderInfoProvider.CreateEmailMacroResolver(cartObj);

string resolvedBody = resolver.ResolveMacros(body);

Best regards,
Michal Legen