Developer forum
E-mail notifications
Orderlines sorting
Replies
Hi there,
I haven't fully tested the solution below, but I think you can accomplish this with an OrderTemplateExtender that grabs the lines, sorts them and reassigns them to the order. The following should work:
public class SortProductsExtender : OrderTemplateExtender
{
public override void ExtendTemplate(Template template, TemplateExtenderRenderingState renderingState)
{
if (renderingState == TemplateExtenderRenderingState.Before)
{
List<OrderLine> tempList = new List<OrderLine>();
foreach (OrderLine orderLine in Order.OrderLines)
{
tempList.Add(orderLine);
}
tempList = tempList.OrderByDescending(o => o.ID).ToList();
Order.OrderLines.Clear();
foreach (OrderLine item in tempList)
{
Order.OrderLines.Add(item);
}
}
}
}
You need at least references to System.Linq and System.Collections.Generic to make this work.
Hope this helps,
Imar
BR.
Lars
foreach (OrderLine item in tempList.Where(ol => ol.Type != "3"))
{
Order.OrderLines.Add(item);
}
foreach (OrderLine item in tempList.Where(ol => ol.Type == "3"))
{
Order.OrderLines.Add(item);
}
Cheers,
Imar
I will try this.
Regards
Thomas
You must be logged in to post in the forum