Updating Order item properties

In this article we will show how to update the properties of the Order items in the submitted order, for example the item name (OrderItemName).
In your E-Commerce scenarios, you may need to mark the order items in the list with some additional text or similar. Thanks to the custom providers customization model, most requirements can be easily implemented.

However, the current design in OrderItem properties is that, a customization by simply setting the property will overwrite original product (SKU record) property too, due to how the data serialization is made.

The following example code will ensure that only the OrderItem properties are updated. In this example, we will use the SKU/OrderItem Name and Number properties.

The key thing is to first serialize the data and set the property OrderItemSKU to null - so that we don't overwrite the SKU. Then we set the ID, Name, etc. and serialize again.

Code of the example custom OrderItemInfoProvider:
Usings section is as follows:
using System; using System.Data; using CMS.CMSHelper; using CMS.DataEngine; using CMS.GlobalHelper; using CMS.SettingsProvider; …

Then we have an override of the default SetOrderItemInfoInternal method:
protected override void SetOrderItemInfoInternal(OrderItemInfo itemObj) { // If SKU object exists if (itemObj.OrderItemSKU != null) { int skuId = itemObj.OrderItemSKUID; // Keep SKU ID up to date itemObj.OrderItemSKU.SKUID = skuId; string name = itemObj.OrderItemSKUName; string number = itemObj.OrderItemSKU.SKUNumber; // Save SKU XML data itemObj.SetValue("OrderItemSKU", itemObj.OrderItemSKU.ToXML(CMSObjectHelper.GetTableName(itemObj.OrderItemSKU), false)); itemObj.OrderItemSKU = null; itemObj.OrderItemSKUID = skuId; // Here we add a number to the name, for example itemObj.OrderItemSKUName = name + " [" + number + "]"; itemObj.SetValue("OrderItemSKU", itemObj.OrderItemSKU.ToXML(CMSObjectHelper.GetTableName(itemObj.OrderItemSKU), false)); } else { // Clear SKU XML data itemObj.SetValue("OrderItemSKU", null); } SetInfo(itemObj); }

Applies to: Kentico CMS 7.x
Share this article on   LinkedIn