How to display OrderItem CustomData in invoice

lucas han asked on June 26, 2014 21:04

I need to display the OrderItem's CustomData in invoice, the project is done by other people before. In the previous invoice template, it used "{#OrderCustomData#}" to display the item's cusmtomdata which was working fine.

Then I added a new key called "State" to the CustomData and the data was stored in database. The question is how can I make the "state" display on the invoice?

Thanks in advance

Recent Answers


Josef Dvorak answered on September 22, 2014 14:58 (last edited on December 10, 2019 02:30)

Hi Lucas,

The Order custom data can by displayed using either of these macros:

{% Order.OrderCustomData.State |(identity)GlobalAdministrator%} in transformation Order_ContentTable.

The ContentTable is created using method CreateContentTableInternal, and each item row filled using method CreateContentRowInternal in the ShoppingCartInfoProvider. Using Custom Info Provider, you can override the methods like this, to define and add a value for any custom column:

/// <summary>
/// Creates an empty shopping cart content table.
/// </summary>     
protected override DataTable CreateContentTableInternal()
{
    DataTable dt = base.CreateContentTableInternal()
    dt.Columns.Add(new DataColumn("CustomState", typeof(string)));
    return dt;
}

/// <summary>
/// Creates one row of the content table with the data which are retrieved from the specified shopping cart item.
/// </summary>
/// <param name="item">Shopping cart item</param>
/// <param name="table">Table from which the content row is created</param>
protected override DataRow CreateContentRowInternal(ShoppingCartItemInfo item, DataTable table)
{
    DataRow row = base.CreateContentRowInternal(item, table);
    row["CustomState"] = item.CartItemCustomData.State;
    return row;
}

Note the use of CartItemCustomData instead of OrderItemCustomData. This ContentTable is shared between the invoice and the Shopping Cart content dialogue, so doing this will also allow you to read this value in the shopping cart.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.