Extending General Settings

Follow

General Settings can easily be extended to store site specific configuration data in Sitecore.

First, you will create a new configuration class that inherits from ActiveCommerce.Configurations.GeneralSettings. Below is an example that includes a new RuleList field called "Pricing Rules".

namespace ActiveCommerce.Training.PriceTesting.Configuration
{
    public class GeneralSettings : ActiveCommerce.Configurations.GeneralSettings
    {
        [SitecoreField(FieldName="Pricing Rules")]
        public RuleList<PricingRuleContext> PricingRules { get; set; }
    }
}

Then, you just need to register your new class with Unity:

namespace ActiveCommerce.Training.PriceTesting.Loader
{
    public class RegisterTypes : ITypeRegistration
    {

        public void Process(Microsoft.Practices.Unity.IUnityContainer container)
        {
            container.RegisterType(typeof(Sitecore.Ecommerce.DomainModel.Configurations.GeneralSettings), typeof(ActiveCommerce.Training.PriceTesting.Configuration.GeneralSettings), new InjectionMember[] {
                new InjectionProperty("Alias", "General")
            });
        }

        public int SortOrder
        {
            get { return 0; }
        }
    }
}

Now your new field and the base General Settings fields are available to you.

For full context, you can see this extension at work in the PriceTesting training project on Github.

Have more questions? Submit a request

Comments