Add Metafields to OrderSummary view

I need to add extra information on each LineItem of the order. But also to see it on the OrderSummary view on the Commerce UI. Please comment if i can implement a better solution than following approach, because i thought that it could be a fast solution by changing the xml file were we define the order ui like PurchaseOrder-ObjectView.xml

First, defined the Meta Fields and associated with the LineItemEx:

When creating the LineItem, don’t forget to had the new attribute the Properties collection:

 ILineItem lineItem = cart.CreateLineItem(entryContent.Code, _orderGroupFactory);
 lineItem.DisplayName = entryContent.DisplayName;
 lineItem.Properties[MetaFieldNames.LineItem.ReasonCode] = inventoryRecord.ReasonCode;

Change the CommerceManager/Apps/Order/Modules/OrderSummary.ascx file in order to define a new code behind and add a new BoundColumn with DataField=”ReasonCode” that will bind the new MetaField

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="OrderSummary.ascx.cs" Inherits="MyProjectNamespaceSegment.CommerceManager.Apps.Order.Modules.OrderSummary" %>
<div style="padding:10px;">


 <table cellpadding="0" cellspacing="0" width="100%" style="table-layout:fixed;">
        <td colspan="2" style="border: solid 1px #999999;">
            <asp:DataGrid runat="server" ID="MainGrid" .......>
                <HeaderStyle BackColor="#eeeeee" />
                    <asp:BoundColumn DataField="OrderFormId".....></asp:BoundColumn>

                    <asp:BoundColumn DataField="ReasonCode" HeaderText="Reason Code" ItemStyle-CssClass="ibn-vb2" HeaderStyle-CssClass="ibn-vh2"></asp:BoundColumn>

Add to the solution a new OrderSummary.ascx.cs file with the same code has the episerver OrderSummary.ascx.cs existing file. Used ILSpy to get the code from Mediachase.Commerce.Manager.Apps.Order.Modules.OrderSummary.

On the private method BindData, change DataTable colums’ definition to include the new MetaField and the rows added to include LineItem.Properties[New MetaField Name] value.

private void BindData()
    DataTable dataTable = new DataTable
        Locale = CultureInfo.InvariantCulture
    dataTable.Columns.Add(new DataColumn("OrderFormId", typeof(int)));
    dataTable.Columns.Add(new DataColumn("LineItemId", typeof(int)));
    dataTable.Columns.Add(new DataColumn("Code", typeof(string)));
    dataTable.Columns.Add(new DataColumn(MetaFieldNames.LineItem.ReasonCode, typeof(string)));

    using (IEnumerator<IOrderForm> enumerator = orderGroup.Forms.Where((IOrderForm x) => x.Name != OrderForm.ReturnName).GetEnumerator())
        if (enumerator.MoveNext())
            IOrderForm current = enumerator.Current;
            foreach (ILineItem allLineItem in current.GetAllLineItems())
                decimal num = orderGroup.Currency.Round(allLineItem.GetEntryDiscountValue());
                decimal num2 = orderGroup.Currency.Round(allLineItem.GetOrderDiscountValue());
                DataRow dataRow = dataTable.NewRow();
                dataRow[MetaFieldNames.LineItem.ReasonCode] =

Now, i can see the new field on the OrderSummary view:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: