I have an order email confirmation that gets sent out with a transformation used to show products. You can look at my code below
Email Template snippet:
{% 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:
[MacroNamespaceLoader]
public partial class CMSModuleLoader
{
/// <summary>
/// Attribute class that ensures the registration of custom macro namespaces.
/// </summary>
private class MacroNamespaceLoaderAttribute : CMSLoaderAttribute
{
/// <summary>
/// Called automatically when the application starts.
/// </summary>
public override void Init()
{
// Registers "Custom" 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);
}
}