Portal Engine
Version 3.x > Portal Engine > step into OrderItemInfo to manipulate invoice View modes: 
User avatar
Member
Member
mac_sh user - 2/11/2013 12:46:19 PM
   
step into OrderItemInfo to manipulate invoice
Hi. I am running into some difficulty in gaining the actual items within an OrderInfoProvider object. We do our orders somewhat differently in that we include previously paid for items as part of an ongoing membership. This means that the customer may only order two new items but there is a possibility of 4 items appearing. We need to 'override' the order prior to generate invoice so it will appear as the following

item 1 - already paid 0.00
item 2 4.00
item 3 - already paid 0.00

total price: 4.00

I do not actually want to alter the order rows in the database as we use those actual amounts for billing. (we don't want to send items 1,2,3 for only 4.00)

How can I achieve the following. I assumed that I would be able to run a foreach(OrderItemInfo item in Order) but that results in

foreach statement cannot operate on variables of type 'CMS.Ecommerce.OrderInfo' because 'CMS.Ecommerce.OrderInfo' does not contain a public definition for 'GetEnumerator'

public static void Invoice_Generate(int orderId, DataTable orderManifest)
{
DataRow[] alreadyPaying = orderManifest.Select("Already_Paying = true");
OrderInfo order = null;
order = OrderInfoProvider.GetOrderInfo(orderId);
foreach(OrderItemInfo item in order) //How do I manipulate each order item row here prior to invoice generation?
{

Int32 ItemId = item.OrderItemID;
foreach(DataRow Row in alreadyPaying) //91,93,95
{
foreach(DataRow Exists in orderManifest.Rows)
{
if(Convert.ToInt32(Exists["ID"]) == Convert.ToInt32(Row["ID"]) && Convert.ToInt32(Row["ID"]) == ItemId)
{
item.OrderItemUnitPrice = 0;
item.OrderItemSKUName += " Subscribed";
break;
}
}
}
}
order.OrderInvoiceNumber = orderId.ToString();
OrderInfoProvider.SetOrderInfo(order);
if(CMSContext.CurrentSite != null)
{

string invoice = OrderInfoProvider.GetInvoice(orderId, CMSContext.CurrentSite.SiteID);
order.OrderInvoice = invoice;
OrderInfoProvider.SetOrderInfo(order);
}
}


Will this manipulate the physical rows in the database? is there a way to 'backup the rows", manipulate , restore?

thanks.

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 2/20/2013 8:23:17 AM
   
RE:step into OrderItemInfo to manipulate invoice
Hi,

The methods offer in 3.0 Ecommerce is limited, but the custom query won't be needed as there's one query that should work for your aim. Instead of the construction directly over the OrderItem object collection (which is not available in 3.x and even next two versions)...
            foreach(OrderItemInfo item in order) //How do I manipulate each order item row here prior to invoice generation?

The way to get the items of an order is through the ecommerce.orderitem.selectallbyorderid query:
            GeneralConnection conn = ConnectionHelper.GetConnection();
object[,] parameters = new object[1, 3];
parameters[0, 0] = "@OrderId";
parameters[0, 1] = orderId;

// Get dataset with all order items
DataSet ds = conn.ExecuteQuery("ecommerce.orderitem.selectallbyorderid", parameters);

Then you need to loop through the dataset and create the item using DataRow constructor:
            if (ds.Tables.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
OrderItemInfo item = new OrderItemInfo(dr);
//use and process the item as you need
}
}



If you modify the OrderItemInfo objects after the Order is saved, the original SKUs shouldn't be overwritten in the DB. The generation of an invoice is made by instantiating a new ShoppingCartInfo objects from the OrderInfo(with its OrderItems).

Anyway, the current version (7) will offer you the best customization possibilities.

Regards,
Zdenek