Developer forum

Forum » Development » FieldEditor for eCom selection

FieldEditor for eCom selection

Jonas Mersholm
Reply

Hi. I'm trying to make a new FieldEditor to select a product from eCommerce. I followed the guide and it works, so far, for selecting the product. I would like to extend the Fieldeditor though, making it possible to supply what eCom group id to select from in the Item configuration. How do i do this? Where do i add extra fields to fill out when setting up the item type?

 

This is the code:

    [Dynamicweb.Content.Items.Annotations.EditorAttribute("eCom editor")]
    public class ecomItemFieldType : Editor
    {

        public override Type DataType
        {
            get { return typeof(string); }
        }

        public override void BeginEdit(EditorContext context)
        {
            if (context != null && context.Output != null)
            {
                var v = context.Value != null ? context.Value.ToString() : "hilo";
                
                var EcomEmployees = Dynamicweb.eCommerce.Products.Group.GetGroupByID("GROUP188");

                context.Output.WriteLine(string.Format("<select name=\"" + base.Key + "\">", System.Web.HttpUtility.HtmlAttributeEncode(v)));

                // Iterate all products.
                foreach(var Employee in EcomEmployees.Products)
                {
                    // Check if current employee is infact the selected one.
                    string Selected = "";
                    if( Employee.ID.ToString() == v) {
                        Selected = " selected=\"selected\"";
                    }

                    context.Output.WriteLine(string.Format("<option value=\"" + Employee.ID.ToString() +"\" "+Selected+">" + Employee.Name.ToString() +"</option>"));
                }

                context.Output.WriteLine(string.Format("</select>"));
            }
        }

        public override object EndEdit()
        {
            return base.HttpContext.Request[base.Key];
        }
    }
}

 

Thanks in advance.

Jonas


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Jonas

Dynamicweb has a product field already, see dump.

You can add settings by adding a property to your field type and use the field editor attributes for making the setting configurable from the backend.

See http://developer.dynamicweb.com/documentation/for-developers/item-based-structure/using-field-editors.aspx

Also attached Our product field implementation.

Capture.PNG

 

You must be logged in to post in the forum