Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Extending ShoppingCartInfoProvider for custom order information View modes: 
User avatar
Member
Member
Thomasbe-datacom.co - 7/14/2013 12:56:40 AM
   
Extending ShoppingCartInfoProvider for custom order information
Hi,

I am trying to use my own custom gateway provider and I want to store additional information about the order.

I am trying to add custom data to ShoppingCartInfoObj object.

I have created an additional column in the contents table of the ShoppingCartInfoObj object by extending the ShoppingCartInfoProvider as below:

public class DatacomShoppingCartInfoProvider : ShoppingCartInfoProvider 
{
protected override DataTable CreateContentTableInternal()
{
DataTable dt = base.CreateContentTableInternal();
dt.Columns.Add(new DataColumn("TransactionID", typeof(string)));
return dt;
}

protected override DataRow CreateContentRowInternal(ShoppingCartItemInfo item, DataTable table)
{
DataRow row = base.CreateContentRowInternal(item, table);
row["TransactionID"] = item.SKUObj.GetValue("TransactionID");
return row;
}
}


Currently I am setting the transactionid in my override void ProcessPayment()
In my gateway provider.

ShoppingCartInfoObj.ContentTable.Rows[0][" transactionid "] = transactionReference;

And this all works and stores in the content table.

Where it goes wrong is if I stop the order mid-way though and try to run the ProcessPayment() I look into the ShoppingCartInfoObj.ContentTable my custome field is blank and has not kept the information a previously stored.

I thought as ShoppingCartInfoObj still remembers the order information the Contents table would also be remember detail i stored?

Can you tell me if my login is incorrect?

And if so what is the best way to store custom information about an order?
And to have the option to bring back this custom information if the order failed and then was retry for some reason?

Thanks in advanced

Kind Regards,
Thomas

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 7/19/2013 3:28:52 PM
   
RE:Extending ShoppingCartInfoProvider for custom order information
Hi Thomas,

The problem is most probably because the ContentTable can be recalculated without keeping your changes.
If you want to store a custom information for the Order, the best place is to use ShoppingCartCustomData field, an XML structure that can be managed with
SetValue(keyname, value)
and
GetValue(keyname)
methods.
The advantage of this field is that when creating (or updating) an Order, this field contents is stored to OrderCustomData field of the Order object.

An Order doesn't hold the ContentTable from the ShoppingCart. Instead, the ShoppingCartItem (later OrderItem) objects and other properties are serialized in an OrderInfo object and when needed (e.g. repeated invoice generation), the calculation process is done on a ShoppingCart(Info)Object created from the OrderInfo object - there's a method to create a shopping cart object out of an existing order.

By the way, you can also store per-item custom data in ShoppingCartItemInfo.CartItemCustomData or in OrderItemInfo.OrderItemCustomData properties respectively.

Hope this information will help.
Should you need any additional details, please feel free to ask.

Kind regards,
Zdenek