Page 1 of 1

Sorting Order Items List

Posted: Wed Apr 13, 2016 8:45 am
by mharoonbhatti
Is there a way to sort order items based on SKU column.

Shop/admin/orders/Print/PackSlips.aspx

Code: Select all

  OrderShipment shipment = (OrderShipment)dataItem;
            Order order = shipment.Order;
            IList<OrderItem> products = new List<OrderItem>();
            foreach (OrderItem item in order.Items)
            {
                if ((item.OrderItemType == OrderItemType.Product) && (item.OrderShipmentId == shipment.Id))
                {
                    if (item.IsChildItem)
                    {
                        // WHETHER THE CHILD ITEM DISPLAYS DEPENDS ON THE ROOT
                        OrderItem rootItem = item.GetParentItem(true);
                        if (rootItem != null && rootItem.Product != null && rootItem.ItemizeChildProducts)
                        {
                            // ITEMIZED DISPLAY ENABLED, SHOW THIS CHILD ITEM
                            products.Add(item);
                        }
                    }
                    else products.Add(item);
                }
            }
            products.Sort(new OrderItemComparer());
            return products;
I have tried products.Sort("Sku",CommerceBuilder.Common.SortDirection.ASC)

but no luck.

Any help in this regard is greatly appreciated.

Thx,

AbleCommerce GOLD R11

Re: Sorting Order Items List

Posted: Thu Apr 14, 2016 2:12 am
by mazhar
You will have to replace following code

Code: Select all

products.Sort(new OrderItemComparer());
with

Code: Select all

products.Sort("Sku", CommerceBuilder.Common.SortDirection.ASC);
Also if you are using Web Application version then in order make these changes work you will need to build the website project. If you are using Website version then you just need to refresh the page and it should work.