Using order line fields

When a product is added to a cart, it is created as an order line. Order line fields allows the customer to specify more information about an order before checkout.

Order line fields are specific to a certain product. For instance, if a customer wants certain measurements of a product e.g. cables or fabric, an order line field allows the customer to enter how many meters or inches they want of the product. The order line field can be implemented either on the products details page (Figure 1.1)

Figure 1.1 An order line field on a product details page

or in the shopping cart (Figure 1.2). 

Figure 1.2 An order line field in the shopping cart

Before you can use order line fields, you must:

  • Create order line fields in the backend
  • Configure one or more product groups to use the fields
  • Implement the fields in your templates to render the fields in the frontend

After creating an order line field, you must attach it to a product group.

To render the order line fields in the frontend, you must add the following loop to your template if you want the fields to be on the products details page:

Product.OrderLineFields

Or if you want them to be in your shopping cart

Order.OrderLineFields

Notice that if you want the order line fields loop to be in the shopping cart, the loop should be placed inside the OrderLines loop as well. Rendering the order line fields in a shopping cart could look like this:

@foreach (var line in GetLoop("OrderLines")) { <tr data-product-auto-id='@line.GetValue("Ecom:Product.AutoID")'> <td class="name"> <a href='@line.GetValue("Ecom:Order:OrderLine.ProductLink")'> @line.GetValue("Ecom:Order:OrderLine.ProductName.Short") @if (!string.IsNullOrWhiteSpace(line.GetString("Ecom:Order:OrderLine.ProductVariantText"))) { @: (@line.GetString("Ecom:Order:OrderLine.ProductVariantText")) } </a> </td> <td class="quantity">@line.GetValue("Ecom:Order:OrderLine.Quantity")</td> @foreach (LoopItem item in @line.GetLoop("Order.OrderLineFields")){ <td class="orderlinefields">@item.GetString("Ecom:Order:OrderLine.OrderLineField.Name"): @item.GetString("Ecom:Order:OrderLine.OrderLineField.InputTextField")<br></td> }

For more informations about the loops, see the Template Tags-site.