I have an order email confirmation that gets sent out with a transformation used to show products. You can look at my code below
{% Order.OrderItems.ApplyTransformation("custom.Transformations.OrderConfirmationLineItem") #%}
Then within that transformation I am trying to use a custom macro I created, but I can't seem to get the custom macro to work. I've used the system console app to see if my macro was being loaded into the global macro resolver and it works fine in there, but can't figure out why it doesn't work in my transformation.
Below is the custom macro I'm using in my transformation. OrderItemText is where the SKUId is being stored.
Transformation:
{% Custom.GetSampleSKU(OrderItemText).SKUName #%}
Here is my code for registering the custom macro:
" into the macro engine
MacroContext.GlobalResolver.SetNamedSourceData("Custom", CustomMacroNamespace.Instance);
}
}
}
Here is my custom macro:
[assembly: RegisterExtension(typeof(CustomMacroMethods), typeof(CustomMacroNamespace))]
public class CustomMacroMethods : MacroMethodContainer
{
[MacroMethod(typeof(SKUInfo), "Gets the SKU of a sample product", 1)]
[MacroMethodParam(0, "param1", typeof(string), "SKUID of the product")]
public static object GetSampleSKU(EvaluationContext context, params object[] parameters)
{
int id = 0;
// Branches according to the number of the method's parameters
switch (parameters.Length)
{
case 1:
id = ValidationHelper.GetInteger(parameters[0], 645);
break;
case 2:
id = ValidationHelper.GetInteger(parameters[1], 645);
break;
default:
// No other overloads are supported
throw new NotSupportedException();
}
return SKUInfoProvider.GetSKUInfo(id);
}
}
Turns out the custom order info provider I was using needed to add my macro provider to it's resolver. After I added that the macro was resolved in my email.
Jon,
Where there is not enough information above to let us look at your code well, my first question would be if you remove the custom macro and just try to resolve the OrderItemText field in your transformation does that show the value you are expecting? Also since this is a text field and not an integer field yet you are storing an integer in it (so you explain above), are you making sure your code is seeing it as an integer to grab the SKUName?
Also why are you storing the SKUID in the OrderItemText field vs just using the OrderItemSKUID field? Maybe I am just missing something.
@Virgil I have tried just outputing the OrderItemText field and that works just fine, but the macro resolves to nothing. I convert the string to an interger when using the SKUInfoProvider class. We are storing a reference to another SKU within that field and need to grab details of it in the email template.
What's strange to me is that it outputs nothing at all, like it never calls the method or throws an error. I'll add some more code to my original question.
Please, sign in to be able to submit a new answer.