Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > About Custom Marco in Ecommerce E-mail Template View modes: 
User avatar
Member
Member
shenyi_1987-hotmail - 10/25/2012 9:01:27 PM
   
About Custom Marco in Ecommerce E-mail Template
Hello:

I just want to change the display of product details in ecommerce notification email.

The old display is:
Product Name Units Unit Price Tax Total Price
Product1 1 10.00 1.00 11.00
-Product1-option 1 2.00 0.20 2.20

I want to change it into:
Product Name Units Unit Price Tax Total Price
Product1 1 12.00 1.20 13.20
-Product1-option


I tried to follow document devnet.kentico.com/docs/6_0/ecommerceguide/customizing_invoice_and_email_templates.htm
But to be honest, I don't know how to do that. I'm confused where to put the code, in App_Code folder, create a new cs file, or something else? And how to register the custom macro? I also had a look of dev guid of macro expression, but I also don't know what to do. Is there anywhere that I can find a complete sample?

Then I tried to use custom marco method to achieve that.
The old macro in e-mail template is :ContentTable.ApplyTransformation(...);
I deleted it and change into my own macro:
{%OrderInfo(Order.OrderID)%}
but display nothing.

Below is my macro code:
MacroMethods.RegisterMethod("OrderInfo", OrderInfo, typeof(string), "Returns concatenation of two strings.", null, 1, new object[,] { { "param1", typeof(int), "1" } }, null);

public static string OrderInfo(int param1)
{
string result = "";
DataSet ds=OrderItemInfoProvider.GetOrderItems(param1);
DataTable dt= ds.Tables[0];
int index = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows["IsProductOption"].ToString() == "False")
{
index = i;
}
else
{
dt.Rows[index]["UnitPrice"] = (double.Parse(dt.Rows[index]["UnitPrice"].ToString()) + double.Parse(dt.Rows["UnitPrice"].ToString())).ToString();
dt.Rows[index]["TotalTax"] = (double.Parse(dt.Rows[index]["TotalTax"].ToString()) + double.Parse(dt.Rows["TotalTax"].ToString())).ToString();
dt.Rows[index]["TotalPrice"] = (double.Parse(dt.Rows[index]["TotalPrice"].ToString()) + double.Parse(dt.Rows["TotalPrice"].ToString())).ToString();
dt.Rows["UnitPrice"] = 0;
dt.Rows["TotalTax"] = 0;
dt.Rows["TotalPrice"] = 0;
}
}
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows["IsProductOption"].ToString() == "False")
{
result+="<tr>";
result+="<td style=\"text-align: left\">"+dt.Rows["SKUName"].ToString();
result+="</td>";
result+="<td>"+dt.Rows["Units"]+"</td>";
result+="<td>"+dt.Rows["UnitPrice"]+"</td>";
result+="<td>"+dt.Rows["TotalTax"]+"</td>";
result+="<td>"+dt.Rows["TotalPrice"]+"</td>";
result+="</tr>";
}
else
{
result+="<tr>";
result+="<td style=\"text-align: left\"> -"+dt.Rows["SKUName"].ToString();
result+="</td>";
result+="</tr>";
}
}
return result;
}

 public static object OrderInfo(params object[] parameters)
{
switch (parameters.Length)
{
case 1:
// Overload with one parameter
return OrderInfo(ValidationHelper.GetInteger(parameters[0], 0));

default:
// No other overload is supported
throw new NotSupportedException();
}
}

CustomMacroMethods.RegisterMethods();

What's wrong in the code? I really cannot understand the docs.

thanks a lot.

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 11/4/2012 2:08:13 AM
   
RE:About Custom Marco in Ecommerce E-mail Template
Hello,

I'm not pretty sure what have you chaged. But please, take a look at our Developers guide for better explanation and understanding of macros, there you can find also nice example how to create a custom macro (via MacroResolver).

For me it seems like you were trying some mixture of macros and transformations.

But of course you can use Transformations in macro expressions.

Registering macro doesn't create an available custom macro, it's used for "IntelliSense" auto-completion.
I would recommend you to create a new transformation and modify the default one.

I hope that developers guide will make Kentico's documentation a little bit clearer.

Best regards,
Martin Danko