Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > CUSTOM MACROS w paramater in EMAIL TEMPLATE View modes: 
User avatar
Member
Member
eagleag - 3/13/2011 4:36:49 PM
   
CUSTOM MACROS w paramater in EMAIL TEMPLATE
Hi,
I have an ecommerce site and email template.
on order this email is sent out: E-commerce - Order notification to customer,
and Im trying to add a custom macros w a parameter to the template.
I am getting an error:

this is how the doe looks:
{#getVat|%TOTALPRICE%#}

+ actual custom macros

match = false;
string result = expression;


switch (expression.ToLower())
{


case "getvat":
match = true;
double vat1 = 1.16;
double fullPrice1 = Convert.ToDouble(temp[1].Split('&')[0]);
double priceNoVat1 = fullPrice1 / vat1;
result = String.Format("{0:0.##}", (fullPrice1 - priceNoVat1)); // (fullPrice1 - priceNoVat1).ToString();
break;
}

return result;


When i run this locally and debug I that all is good, but on live site I get the error:

[FormatException: Input string was not in a correct format.]
System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +10161091
System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt) +204

System.Double.Parse(String s, NumberStyles style, NumberFormatInfo info) +10148255
System.Convert.ToDouble(String value) +48
CMSCustom.ResolveCustomMacro(MacroResolver sender, String expression, Boolean& match) +279
CMS.GlobalHelper.MacroResolver.MacroMatch(Match m, Boolean& match) +2293
CMS.GlobalHelper.MacroResolver.MacroMatch(Match m) +28
System.Text.RegularExpressions.RegexReplacement.Replace(MatchEvaluator evaluator, Regex regex, String input, Int32 count, Int32 startat) +244
System.Text.RegularExpressions.Regex.Replace(String input, MatchEvaluator evaluator) +84
CMS.GlobalHelper.MacroResolver.ResolveMacros(String inputText, Int32 recursionLevel) +723
CMS.CMSEcommerce.OrderInfoProvider.SendOrderNotificationToCustomer(ShoppingCartInfo cartObj) +406
CMSModules_Ecommerce_Controls_ShoppingCartPreview.ProcessStep() in
c:\inetpub\wwwroot\stop\Extensions\CMSModules\Ecommerce\Controls\ShoppingCart\ShoppingCartPreview.ascx.cs:327
CMS.EcommerceProvider.ShoppingCart.ButtonNextClickAction() +62
CMSModules_Ecommerce_Controls_ShoppingCartControl.btnNext_Click(Object sender, EventArgs e) +235
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981


When I changed the macros code to just return whatever the parameter is that it received, I got this:
%TOTALPRICE%


Any ideas why isn't working on live?
All files are in sync just like local?
Could I be missing some setting?server?

THANKS :)

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 3/15/2011 5:38:37 AM
   
RE:CUSTOM MACROS w paramater in EMAIL TEMPLATE
Hi,

you can use following code in your custom macro to get totalprice value:



switch (expression.ToLower())
{
case "custom":
match = true;

// Get shopping cart object from resolver
CMS.Ecommerce.ShoppingCartInfo cartObj = sender.SourceObject as CMS.Ecommerce.ShoppingCartInfo;
double price = Convert.ToDouble(cartObj.TotalPrice);

// add your code

result = price.ToString();
break;
}


Best regards,
Ivana Tomanickova