How to associate a Content Types to a Catalog Product? - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

How to associate a Content Types to a Catalog Product?

  • How to associate a Content Types to a Catalog Product?
  • I'm trying to associate a List/Array of Content Types to a Product, i.e, i have several content types and when creating a Product, on Sitefinity Ecommerce, i need to associate this Product with several content types. So far i created a Dynamic Field Selector to select several conten types on the Product, this works fine until the moment i try to save it and a serialization error is thrown since i can't set the Type of this field as a Guid[], like on Content Types fields, so i selected as long text. But since it's trying to convert a Guid[] to string it throws a error.

    Anyone as any ideia on how to do this or a hint so i can follow up?

  • Hi Squall,

    The best thing you could do is use Sitefinity 7.0 once it comes out (which is going to happen in the following week or two the most), where the feature to associate any content type with any content type (interface included) comes out-of-the-box.

    Grisha 'Greg' Karanikolov
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
  • Hi Greg,

     Thanks fro the reply, isn't it possible somehow to do it in Sitefinity 6.3? Programmatically or not?

  • Ok, i got this working...below are the steps i took.

     I basically used this site: and

    To programmatically add the field, but for some reason it didn't add the field for the views (Edit and Insert) so i had to add them by hand. Below i will show what i did with more detail.First i generated a Sitefinity Dynamic Items Field Control Selector through Sitefinity Thunder, see 2nd link for more information on how to do this.

    On Global.asax.cs i added this code:

    private void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)

        // Register the dynamic field selector
        if (e.CommandName == "Bootstrapped")

    "Telerik.Sitefinity.DynamicTypes.Model.sf_ec_prdct_skillsoftpack", "Assets");

    public static void RegisterFieldForProduct<T>(string productType, string fieldName)
    where T : FieldControlDefinitionElement

    // Check if the field is not already present for this content type
    var catalogManager = CatalogManager.GetManager();
    var itemClrType = TypeResolutionService.ResolveType(productType);

    // Specify the persistent filed CLR type (e.g. String, Guid[], ContentLink).
    // Please ensure your custom field has been properly implemented to work with that CLR type
    var persistentFieldType = typeof(Guid[]);
    var itemType = itemClrType.FullName;

    // Check to see if the field exists
    var fieldExists = GetMetaFieldsForType(itemType).SingleOrDefault(f => f.FieldName == fieldName) != null;
    if (fieldExists) return;

    // Add the metafield that will hold the data
    .TryCreateNew(fieldName, persistentFieldType)

    // Get correct module configuration depending on item type
    var manager = ConfigManager.GetManager();

    // Suppress the security
    var suppressSecurityChecks = manager.Provider.SuppressSecurityChecks;
    manager.Provider.SuppressSecurityChecks = true;

    // Get Backend views(e.g. Edit, Create) configuration from ProductsBackendDefinitionName
    var section = Config.Get<ContentViewConfig>();
    const string definitionName = "ProductsBackendDefinitionName";
    var backendSection = section.ContentViewControls[definitionName];
    var views = backendSection.ViewsConfig.Values.Where(v => v.ViewType == typeof(DetailFormView));

    foreach (DetailFormViewElement view in views)

    if (view.ViewName.Contains("sf_ec_prdct_skillsoftpack") == true)

    // If there are no custom fields added before, the new field will be placed in the CustomFieldsSection
    var sectionToInsert = CustomFieldsContext.GetSection(view, CustomFieldsContext.customFieldsSectionName, itemType);
    var fieldConfigElementType = TypeResolutionService.ResolveType(typeof(T).FullName);

    // Create a new instance of our field configuration in the current view configuration
    var newElement = Activator.CreateInstance(fieldConfigElementType, new object[] sectionToInsert.Fields ) as T;

    // Populate custom field values
    if (newElement == null) continue;

    newElement.DataFieldName = fieldName;
    newElement.FieldName = fieldName;
    newElement.Title = fieldName;
    newElement.DisplayMode = FieldDisplayMode.Write;


    // Save and restart the application
    manager.Provider.SuppressSecurityChecks = suppressSecurityChecks;

    On Sitefinity BackEnd i had to add the field view by hand, Administration->Settings->Advanced->Catalog->ProductsBackendDefinitonName->Views->insert_view->Sections->Main Section->Fields

    Here i selected create new, choose AssetsDefinitionName (my Content Type Definition Name), then i only added information to this fields:

    DataFieldName -> Assets (My field name)

    Write-> WriteField Name -> Assets (My field name)

    Field Type -> SitefinityWebApp.Fields.Assets.AssetsSelector, SitefinityWebApp (My Dynamic Items Field Control Selector)

    Then i repeated the same to the other view (edit_view).

    After this i could associate a list of content type to a specific product. I think it was pretty much this, hope i didn't forgot any step.