Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Handlers and helpers associated with custom address fields

Describes handlers and helpers associated with custom address fields in Optimizely Configured Commerce.

Available handlers and helpers

This article is an association with the Configurable Customer Address Fields article.

The data for the configurable address fields are populated within the BillTo and ShipTo handler chains. The following CustomerHelper methods are actually responsible for aggregating, formatting, and returning validating information for use by the BillTo and ShipTo address forms on the Storefront.

CustomerValidationDto PopulateBillToValidation(IUnitOfWork unitOfWork, GetCustomerSettingsResult settings, Customer billTo);
        CustomerValidationDto PopulateShipToValidation(IUnitOfWork unitOfWork, GetCustomerSettingsResult settings, Customer billTo, Customer shipTo, bool isNew = false);

These methods are currently used in the BillTo and ShipTo handler chains. An example of their use can be seen below.

var userAndBillToResult = this.CustomerHelper.GetUserAndBillTo(
  unitOfWork, // This should be injected in the constructor.
  result,     // This is returned by the handler chain.
  ...         // The rest of the arguments should come from a parameter to the handler.
);


var customerSettings = this.HandlerFactory.GetHandler<IHandler<GetSettingsParameter, GetCustomerSettingsResult>>().Execute(
  unitOfWork,
  new GetSettingsParameter(),
  new GetCustomerSettingsResult());
   this.CustomerHelper.PopulateBillToValidation(
    unitOfWork,
    customerSettings,
    userAndBillToResult.BillTo);

Use a custom handler to access the validation data

If you want to get access to the generated validation data, an easy way is to inject a custom handler into the chain of responsibility. The following handlers populate validation data for use by either the BillTo or ShipTo address forms.

HandlerOrderComment
GetBillToHandler500Populates validation for the BillTo address form.
GetShipToHandler500Populates validation for the ShipTo address form.

Below is an example custom handler that can be used to get access to the generated validation data:

[DependencyName("ModifyBillToValidationHandler ")]
public class ModifyBillToValidationHandler : HandlerBase<GetBillToParameter, GetBillToResult>
{
  public override int Order => 501; // The order number must be higher to come after the GetBillToHandler in the handler chain.
 
  public override GetBillToResult Execute(IUnitOfWork unitOfWork, GetBillToParameter parameter, GetBillToResult result)
  {
    // You can modify the validation data here.
    // result.Validation now holds the validation data populated by the GetBillToHandler
  }
}