Adding custom field to order
I tried adding a custom field to order using:
App.WorkWith().DynamicData().Type(
typeof
(Order)).Field().TryCreateNew(
"affiliateCode"
,
typeof
(
string
)).SaveChanges(
true
);
Specified type 'Telerik.Sitefinity.Ecommerce.Orders.Model.Order' is not a dynamic type.
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();
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()
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.