Set extension property for commerce order
using Microsoft.Dynamics.Commerce.Runtime.Services.CustomerOrder;
using Microsoft.Dynamics.Commerce.Runtime.DataModel;
/// <summary>
/// Extension of <b>RetailTransactionTransformer</b> class
/// </summary>
[ExtensionOf(classStr(RetailTransactionTransformer))]
final class RetailTransactionTransformerCls_POL_Extension
{
/// <summary>
/// Convert retail sales transaction into <b>ItemInfo</b> object
/// </summary>
public static ItemInfo ReadOneTransactionSalesTrans(RetailTransactionTable transactionTable, RetailTransactionSalesTrans salesTrans)
{
ItemInfo itemInfo = next ReadOneTransactionSalesTrans(transactionTable, salesTrans);
ExtensionPropertyCollection extensionPropertyCollection = itemInfo.ExtensionProperties;
CommerceProperty splitPropery = new Microsoft.Dynamics.Commerce.Runtime.DataModel.CommerceProperty(fieldStr(RetailTransactionSalesTrans, <CustomField>), enum2int(salesTrans.<CustomField>));
CommerceProperty comment = new Microsoft.Dynamics.Commerce.Runtime.DataModel.CommerceProperty(fieldStr(RetailTransactionSalesTrans, comment), salesTrans.comment);
extensionPropertyCollection.Add(splitPropery );
extensionPropertyCollection.Add(comment);
return itemInfo;
}
/// <summary>
/// This method is used to read sales transactions for return.
/// </summary>
public static ItemInfo ReadOneTransactionSalesTransForReturn(
RetailTransactionTable transactionTable,
RetailTransactionSalesTrans salesTrans)
{
ItemInfo itemInfo = next ReadOneTransactionSalesTransForReturn(transactionTable, salesTrans);
ExtensionPropertyCollection extensionPropertyCollection = itemInfo.ExtensionProperties;
CommerceProperty customLineNumber = new Microsoft.Dynamics.Commerce.Runtime.DataModel.CommerceProperty(fieldStr(RetailTransactionSalesTrans, customPortalLineNum), salesTrans.customPortalLineNum);
extensionPropertyCollection.Add(customLineNumber );
return itemInfo;
}
/// <summary>
/// Convert a transaction data into customer order info.
/// </summary>
public static CustomerOrderInfo ConvertTransactionToCustomerOrderInfo(RetailTransactionTable transactionTable)
{
CustomerOrderInfo customerOrderInfo = next ConvertTransactionToCustomerOrderInfo(transactionTable);
var extensionPropertyCollection = customerOrderInfo.ExtensionProperties;
CommerceProperty custPurchaseOrder = new Microsoft.Dynamics.Commerce.Runtime.DataModel.CommerceProperty(fieldStr(RetailTransactionTable, CustPurchaseOrder), transactionTable.CustPurchaseOrder);
CommerceProperty isImport= new Microsoft.Dynamics.Commerce.Runtime.DataModel.CommerceProperty(fieldStr(RetailTransactionTable, isImport), enum2Str(transactionTable.isImport));
extensionPropertyCollection.Add(custPurchaseOrder);
extensionPropertyCollection.Add(isImport);
return customerOrderInfo;
}
}
using Microsoft.Dynamics.Commerce.Runtime.Services.CustomerOrder;
/// <summary>
/// To update sales order while creating through sync orders from retail
/// </summary>
[SubscribesTo(classStr(RetailTransactionServiceOrders), staticDelegateStr(RetailTransactionServiceOrders, beforeCreatingRetailOrderLines))]
public static void RetailTransactionServiceOrders_beforeCreatingRetailOrderLines(SalesTable _salesTable, Microsoft.Dynamics.Commerce.Runtime.Services.CustomerOrder.CustomerOrderInfo _customerOrderInfo)
{
var extensionPropertyCollection = _customerOrderInfo.ExtensionProperties;
Microsoft.Dynamics.Commerce.Runtime.DataModel.CommercePropertyValue propertyValue;
boolean update = false;
for (int i=0; i < extensionPropertyCollection.get_Count(); i++)
{
var commerceProperty = extensionPropertyCollection.get_Item(i) as Microsoft.Dynamics.Commerce.Runtime.DataModel.CommerceProperty;
switch(commerceProperty.Key)
{
case fieldStr(RetailTransactionTable, custPurchaseOrder):
propertyValue = commerceProperty.Value;
_salesTable.PurchOrderFormNum = propertyValue.StringValue;
update = true;
break;
case fieldStr(RetailTransactionTable, <CustomField>): //Enum
propertyValue = commerceProperty.Value;
NoYesId noYesId;
_salesTable.<CustomField> = str2Enum(noYesId,propertyValue.StringValue);
update = true;
break;
case fieldStr(RetailTransactionTable, <CustomField>):
propertyValue = commerceProperty.Value;
_salesTable.<CustomField>= propertyValue.StringValue;
break;
}
}
if(update)
{
_salesTable.doUpdate();
}
}