Hi DWs
One of our clients want the basket orderlines sorted in product number desc.
Is this in anyway possible as standard?
//Peter
Hi DWs
One of our clients want the basket orderlines sorted in product number desc.
Is this in anyway possible as standard?
//Peter
Hi Peter
In an OrderTemplateExtender:
You have access to the orders object. On the order object you have an Orderlines Collection which can be sorted:
Before calling sort, set the sortfield and sortorder:
Only way...
BR Nicolai
When using sortbyfield is it always Ascending.?
Yes ASC is default, but can be overridden.
But what I provided you is wrong, because that is on the order collection and not the orderline collection...
So, you would have to create a custom collection of orderlines, move them from order.orderlines, sort them, clear the order.orderlines Collection and then add them in the right order.
Difficult and Things could go wrong...
BR Nicolai
Oki, I will recommend the client some smaller jquery solution and then order mail and print will be default.
Hi Peter,
It is fairly easy to rearrange the orderlines - I hope that you can use this example:
public class SortProductsExtender : OrderTemplateExtender { public override void ExtendTemplate(Template template) { if (RenderingState == TemplateExtenderRenderingState.Before) { // Load orderlines into temporary list List<OrderLine> tempList = new List<OrderLine>(); foreach (OrderLine orderLine in Order.OrderLines) { tempList.Add(orderLine); } // Reorder the orderlines tempList = tempList.OrderByDescending(ol => ol.ProductNumber).ToList(); // Remove current orderlines Order.OrderLines.Clear(); // Add the reordered lines to the orderlines of the order foreach (OrderLine item in tempList) { Order.OrderLines.Add(item); } } } }
Best regards, Anders
Just remember to test this if you have discounts or parts list involved. They would be suborder lines and could be messed up by sorting.
Nicolai
ok, will test it with all possible aspects. Thanks for help, code and comments.
You must be logged in to post in the forum