Monday, November 28, 2016

Adding New MetaDataPlus Dictionary Field and Assigning it to Catalog Entry Class

We will be adding new catalog entry class and will be assigning new meta dictionary field with multiple values.

Adding new Catalog Entry (ProductBase) Class

    [CatalogContentType(GUID = "C39413F3-310C-49C6-A4C4-6B86D6788401", MetaClassName = "ProductBase")]
    public class ProductBase  : ProductContent
        [Display(Order = 60)]
        public virtual string ProductType { get; set; }

Now we will be defining initializing class to add new meta field and assign it to Catalog Entry(ProductBase) class

 public class CatalogInitialization : IConfigurableModule
  private bool _isInitialized;

  public void Initialize(InitializationEngine context)
   if (_isInitialized)


   _isInitialized = true;

  public void Uninitialize(InitializationEngine context)
   _isInitialized = false;

  public void ConfigureContainer(ServiceConfigurationContext context)
   context.Container.Configure(ctx => ctx.AddRegistry());

  private static void SyncMetaClassAndField()
    var metaProClass = Mediachase.MetaDataPlus.Configurator.MetaClass.Load(MetaDataContext.Instance, "ProductBase");
                  MetaField metaProp = MetaField.Load(MetaDataContext.Instance, "ProductType");

      if (metaProp == null)
                      metaProp = Mediachase.MetaDataPlus.Configurator.MetaField.Create(MetaDataContext.Instance, "Mediachase.Commerce.Catalog", "ProductType", "Product Type", "Product Type Description", MetaDataType.DictionarySingleValue, 1000, false, false, false, false);
                  metaProp.Dictionary.Add("Baby", "Baby");
                  metaProp.Dictionary.Add("Toddler", "Toddler");
                  metaProp.Dictionary.Add("Junior", "Junior");
                  metaProp.Dictionary.Add("Walker", "Walker");

No comments:

Post a Comment