Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Add handlers to return custom properties to a service

Describes how to add handlers to return custom properties to a service in Optimizely Configured Commerce.

This article demonstrates how to display custom properties in the browser. This requires adding a new handler to the chain of responsibility and adding custom data to the model.

The example shows how to add an organization code custom properties to a user profile.

  1. Open Visual Studio and add a new class for the new handler. Name: GetAccountHandler_Custom.cs

  2. Derive from the HandlerBase<GetAccountParameter, GetAccountResult>

  3. Add an OrgCode custom property to the collection property of the return object. This can be done by using CurrentContextUserProfile.GetProperty("OrgCode")

  4. Set the Order to 600 so that the base handler is called first in the chain

    [DependencyName("GetAccountHandler_Custom")]
    public class GetAccountHandler_Custom : HandlerBase<GetAccountParameter, GetAccountResult>{
        protected readonly IAccountHelper AccountHelper;
    
        public GetAccountHandler_Custom(IAccountHelper accountHelper)
        {
            this.AccountHelper = accountHelper;
        }
    
        public override GetAccountResult Execute(InSite.Model.Interfaces.IUnitOfWork unitOfWork, 
                GetAccountParameter parameter, GetAccountResult result)
        {
            result.Properties.Add("OrgCode", 
                this.CurrentContext.UserProfile.GetProperty("OrgCode", "Insite"));
    
            return this.NextHandler.Execute(unitOfWork, parameter, result);
        }
    
        public override int Order
        {
            get { return 600; }
        }
    }
    
  5. The code has now been complete and now the user interface needs to be updated to display the organization code. In this example we will update the existing theme but it is recommended to derive a new theme and directive.

  6. Add the following line to the AccountSettings.cshtml directive under the <h3> at the top of the page.

    <h4>{{vm.account.properties['OrgCode']}}</h4>
    
  7. Rebuild the solution and view the results. The OrgCode can now be managed from within the Admin Console