More in this section

Forums / Developing with Sitefinity / Adding custom field to order

Adding custom field to order

4 posts, 1 answered
  1. Pierre Alain
    Pierre Alain avatar
    38 posts
    Registered:
    10 Jun 2008
    19 Mar 2012
    Link to this post
    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?
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    20 Mar 2012
    Link to this post
    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
    Answered
  3. Pierre Alain
    Pierre Alain avatar
    38 posts
    Registered:
    10 Jun 2008
    20 Mar 2012
    Link to this post
    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.
  4. Pierre Alain
    Pierre Alain avatar
    38 posts
    Registered:
    10 Jun 2008
    20 Mar 2012
    Link to this post
    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.
4 posts, 1 answered