Adding custom field to order

Posted by Community Admin on 04-Aug-2018 13:45

Adding custom field to order

All Replies

Posted by Community Admin on 19-Mar-2012 00:00

I tried adding a custom field to order using:

App.WorkWith().DynamicData().Type(typeof(Order)).Field().TryCreateNew("affiliateCode", typeof(string)).SaveChanges(true);

but I get this exception:
Specified type 'Telerik.Sitefinity.Ecommerce.Orders.Model.Order' is not a dynamic type.

So I guess it cannot be done. Is this right or am I doing it wrong? Is there another way I can do this?

Posted by Community Admin on 20-Mar-2012 00:00

Hello,

Can you please try first setting the Order type to be Dynamic and then execute your particular code like this:

var metaManager = Telerik.Sitefinity.Data.Metadata.MetadataManager.GetManager();
metaManager.CreateMetaType(typeof(Order));
metaManager.SaveChanges();


Kind regards,
Boyan Barnev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 20-Mar-2012 00:00

Thanks Boyan.

This solved the problem, but now I get an exception when setting the value:

order.SetValue("affiliateCode", affCode);

Object reference not set to an instance of an object.
   at Telerik.Sitefinity.MetafieldPropertyDescriptor.SetValue(Object component, Object value)
   at Telerik.Sitefinity.Model.DataExtensions.SetValue(IDynamicFieldsContainer dataItem, String fieldName, Object value)
   at SitefinityWebApp.Global.EcommerceEvents_OrderPlaced(Guid orderId) in C:\Logicim\Web-sitefinity\Logicim2011\Global.asax.cs:line 61
   at Telerik.Sitefinity.Modules.Ecommerce.EcommerceEvents.RaiseOrderPlacedEvent(Guid orderId)
   at Telerik.Sitefinity.Modules.Ecommerce.Orders.Web.UI.CheckoutViews.Preview.Checkout()

Both order is not null and affCode is a non-null string.

Posted by Community Admin on 20-Mar-2012 00:00

Forget that. I was setting the value right after creating the field.
It works on subsequent calls.
Thank you very much. I'm loving more and more what I can do with Sitefinity.

This thread is closed