Developer forum

Forum » Development » How to implement a ProductFieldTypeProvider

How to implement a ProductFieldTypeProvider

Aki Ruuskanen
Aki Ruuskanen
Reply

Hi,

I'm trying to implement a ProductFieldTypeProvider with a UserGroupParameterEditor. But cannot find any documentation about how to do it. 

I have a class that inherits from ProductFIeldTypeProvider but when i add that in the "Field types" I get the following error:

"UserSelectorSettings is not defined"

Are there any examples on how to implement a ProductFieldType with a UserGroupParameterEditor?

My class so far:

        namespace Softgear.Industrilas.Data.Provider
        {
            [AddInName("Mindflower.UserGroupSelectProvider")]
            [AddInLabel("User Group Selector")]
            [AddInActive(true)]
            [Serializable]
            public class UserGroupSelectProvider : ProductFieldTypeProvider, IDropDownOptions
            {
                private Lazy<Dictionary<string, string>> _options;

                

                public UserGroupSelectProvider()
                {
                    _options = new Lazy<Dictionary<string, string>>();
                }

                public override object GetValue(object value, string languageId, Dictionary<string, string> settings)
                {
                    return "Testing usergroups";
                }

                public override string GetAppenderInfo(string languageId, string settings)
                {
                    return GetAppenderInfo(languageId, GetParameterValues(settings));
                }

                public override object GetProductValue(Product product, object fieldValue, string languageId, Dictionary<string, string> settings)
                {
                    return "Getting product value";
                }

                public override string GetAppenderInfo(string languageId, Dictionary<string, string> settings)
                {
                    return "In GetAppenderInfo";
                }

                protected override void Render(TextWriter writer, string id, bool enabled, string value, bool hasError, string text, string title)
                {
                    // What should I put here
                }

                [AddInParameter("Usergroups")]
                [AddInParameterEditor(typeof(UserGroupParameterEditor), "multiple=false;")]
                [AddInParameterGroup("Locations")]
                public string[] Usergroups { get; set; }

                public Hashtable GetOptions(string dropdownName)
                {
                    // Get Hashtable
                    Hashtable options = new Hashtable();

                    foreach (var key in _options.Value.Keys)
                    {
                        options.Add(key, _options.Value[key]);
                    }

                    // Return the hashtable
                    return options;
                }

            }
        }

 


Replies

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Aki,

We had a similar situation and we have managed to go around the issue by defining a new class:

public class DfUserGroupParameterEditor : UserGroupParameterEditor
    {
        public override string Render(ConfigurableAddIn addIn, string name, object value, Hashtable options, string label)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine($"<script type='text/javascript' src='/Admin/Images/Controls/UserSelector/UserSelector.js'></script>");
            sb.AppendLine($"<script type='text/javascript' src='/Admin/Resources/js/layout/Actions.js'></script>");            string r =  base.Render(addIn, name, value, options, label);            return $"{sb.ToString()} {r}";
        }
    }

And you can now use DfUserGroupParameterEditor instead of UserGroupParameterEditor

I hope it helps.

Adrian

 
Aki Ruuskanen
Aki Ruuskanen
Reply

Hi Adrian, 

Thanks for the input, it will give it a go. yes

Regards / Aki

 

 

You must be logged in to post in the forum