How to display sub itemes for each orderitem in invoce

benyamin jain asked on June 11, 2018 15:29

HI

I want to know is it possible to display OrderItem Sub itemes in invoice?

Scenario :

Say we sell online ticket that user can buy.tickets have types and each type have it's own set of codes that is defined via a customtable(ex: customtable_ticketcode). for each type of ticket customer add to his shoppingcart we must pick a number of codes from customtable_ticketcode table based on number of units ordered by customer and display code(s) right below orderitem(ticket) in invoice.

A : one way is overriding GetShoppingCartResolverInternal method such as below :

protected override MacroResolver GetShoppingCartResolverInternal(ShoppingCartInfo cart, bool specialMacros)
{
    MacroResolver resolver = base.GetShoppingCartResolverInternal(cart, specialMacros);
    DataTable dt = null;
    if (!OrderHasBarcode(cart))
    {
        // is cart created from an existing order
        if (cart.Order != null && cart.Order.OrderIsPaid)
        {
            InfoDataSet<OrderItemInfo> ds = OrderItemInfoProvider.GetOrderItems(cart.Order.OrderID);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (OrderItemInfo oii in ds)
                {
                    DataSet barCodes = GetNewTicketBarcodes(oii, cart);
                    if (!DataHelper.DataSourceIsEmpty(barCodes))
                    {
                        if (dt == null)
                        {
                            DataColumn[] columns = new DataColumn[barCodes.Tables[0].Columns.Count];
                            barCodes.Tables[0].Columns.CopyTo(columns, 0);
                            dt = GetDataTable(columns);
                        }
                        foreach (DataRow dr in barCodes.Tables[0].Rows)
                        {
                            int itemId = ValidationHelper.GetInteger(dr["ItemID"], 0);
                            CustomTableItem barcode = TicketBarcodeProvider.GetItem(itemId, TicketBarcodeTableClass.ClassName);
                            barcode.SetValue("APTicketTypeOrderID", cart.Order.OrderID);
                            barcode.SetValue("APTicketTypeOrderItemID", oii.OrderItemID);
                            barcode.SetValue("APTicketTypeStatus", "USED");
                            barcode.Update();
                            dt.Rows.Add(dr.ItemArray);
                        }
                    }
                }
                if (dt != null)
                {
                    resolver.SetNamedSourceData("BarcodeTable", dt.Rows);
                }
            }
        }
    }
    else
    {
        DataSet ds = GetTicketBarcodes(cart);
        resolver.SetNamedSourceData("BarcodeTable", ds.Tables[0].Rows);
    }
    return resolver;
}

in this way we can not display Codes that belong to OrderItem right below it by using ApplyTransformation.it display all codes below each order item. NOTE : inside ContentTable item transformation we call BarcodeTable.ApplyTransformation("ecommerce.transformations.barcode_Table").inside barcode_Table transformation we don't have access to OrderItemID to specifiy that only display bacodes for this orderitem.

B : Display all codes right after all cart itemes displayed.(not the case)

Is there any other toimplement this?

Correct Answer

Peter Mogilnitski answered on June 12, 2018 04:46

Not quite sure that I understand what you've explained here. If you want to store something at the order item level you can add a new field (or use existing one OrderItemCustomData). And save your bar code (or watever you need to have there) as JSON (or XML) or any other format you want. Add multiple field if you want to. To add new field to order item: Go to modules -> e-commerce -> classes -> Order item -> Fields and add new field

0 votesVote for this answer Unmark Correct answer

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