Addresses

A user account comes with a set of standard address fields – and in some cases this is enough – but additional addresses can be created for an account when necessary.

This can happen in several ways:

  • From frontend via an instance of the Extranet app in Manage addresses mode
  • From the backend using the built-in Addresses view on a user account
  • As a part of an integration setup where user accounts and addresses are imported from an external system to the AccessUserAddresses table

In frontend you can then make the various addresses available for selection in the shopping cart during checkout – and use e.g. javascript to set the payment and shipping fields to the values from the selected address.

To add additional addresses to a user account from backend:

  1. Open the user account details
  2. Click the Addresses button to switch to the address list (Figure 1.1)
Figure 1.1 The addresses view
  1. Click Add address in the toolbar to open the Edit address view (Figure 1.2)
Figure 1.2 Address fields

As you can see, you have access to a number of standard address fields – they work in exactly the same manner as the corresponding standard user field does.

You also have the option of adding custom address fields.

Custom address fields are used to hold information for which there is no standard field – pretty simple, actually. This can be necessary when working with address data from a region with a different standard address format than the one natively employed by Dynamicweb.

Custom address fields are created by navigating to Settings > Control Panel > Users and clicking Edit custom address fields (Figure 2.1)

This opens the custom address fields view (Figure 2.2) from where you can add new custom fields and specify a name, a system name, and a field type.

Figure 2.2 Custom address fields

Address formats are not universal – in English-speaking countries the postal code usually comes last, on most of Europe the code precedes the town name, and in most of East-Asia addresses start with the Province and ends with the addressee. To make this simpler to reflect in frontend you can create frontend address formats for each Ecommerce country on a solution.

To do so:

  • Go to Settings > Ecommerce > Internationalization > Countries
  • Under Frontend address formats:
    • Switch Address display mode to custom
    • Enter a custom address format
    • Save

You can customize both the Address display format and the Address edit format – in some scenarios, the display format will be different from the edit format, but there are also implementational differences which will be explained later in this section. For now, use the Edit format if you want to create forms using the custom format and the display format if you want to display an address using the custom format.

Once created, the custom address formats can be used whereever you have access to an order ID – the typical scenario of course being in the Shopping Cart app. In the code example below I do the following:

  1. Fetch CountryAddressInfo for an order based on the order ID
  2. Fetch display address fields for the order based on the CountryAddressInfo – this API call returns a list of strings which need only be displayed
  3. Fetch edit address information for the order based on the CountryAddressInfo – this API call returns a list of objects which can be used to create input fields

I then use the data to render display addresses & render a form, as appropriate. The AddressFormatEditRow object also contains properties – like IsCountryField – which can be used to create forms which work in the real world but have been left out of this example for the sake of simplicity.

RAZOR
@{ //Fetch CountryAddressInfo for the order context country (Ecom:Order.Customer.Country). Use true/false to fetch shipping/billing address information var shippingAddressInformation = new Dynamicweb.Ecommerce.International.CountryAddressInfo(GetString("Ecom:Order.ID"), true); var billingAddressInformation = new Dynamicweb.Ecommerce.International.CountryAddressInfo(GetString("Ecom:Order.ID"), false); //Fetch display address fields based on CountryAddressInfo var displayShippingAddressInformation = Dynamicweb.Ecommerce.International.Country.GetDisplayAddress(shippingAddressInformation); var displayBillingAddressInformation = Dynamicweb.Ecommerce.International.Country.GetDisplayAddress(billingAddressInformation); //Fetch edit address information based on CountryAddressInfo var editShippingAddressInformation = Dynamicweb.Ecommerce.International.Country.GetEditAddress(shippingAddressInformation); var editBillingAddressInformation = Dynamicweb.Ecommerce.International.Country.GetEditAddress(billingAddressInformation); } <div class="row col-md-12"> <!--Billing Address--> <div class="col-md-6"> <!--Edit--> <div class="col-md-12 card card-spaced"> <h4>Billing Address Edit Format</h4> <!--Edit-addresses are returned as lists of AddressFormatEditRows objects - this makes it easy to create forms--> <form> @foreach (var addressFormatEditRow in editBillingAddressInformation) { if (!addressFormatEditRow.IsEmpty) { foreach (var addressFormatField in addressFormatEditRow.Fields) { <div class="form-group"> <label for="@addressFormatField.Label">@addressFormatField.Label</label>@addressFormatField. <input type="text" class="form-control" id="@addressFormatField.Label" value="@addressFormatField.Value"> </div> } } } </form> </div> <!--Display--> <div class="col-md-12 card card-spaced"> <h4>Billing Address Display Format</h4> <!--Display addresses are returned as strings which can be rendered directly and styled as you want--> @foreach (var addressString in displayBillingAddressInformation) { <div>@addressString</div> } </div> </div> </div>

Addresses are stored in the AccessUserAddress-table - this does not contain the address stored in the user standard fields.

AccessUserAddress

For users with multiple defined addresses extra addresses are defined here and linked via AccessUserId.

Field name Data type Length
AccessUserAddressId int 4
AccessUserAddressUserId int 4
AccessUserAddressType bit 1
AccessUserAddressCallName nvarchar 255
AccessUserAddressCompany nvarchar 255
AccessUserAddressName nvarchar 255
AccessUserAddressAddress nvarchar 255
AccessUserAddressAddress2 nvarchar 255
AccessUserAddressZip nvarchar 255
AccessUserAddressCity nvarchar 255
AccessUserAddressCountry nvarchar 255
AccessUserAddressPhone nvarchar 255
AccessUserAddressCell nvarchar 255
AccessUserAddressFax nvarchar 255
AccessUserAddressEmail nvarchar 255
AccessUserAddressCustomerNumber nvarchar 255
AccessUserAddressUId nvarchar 50
AccessUserAddressState nvarchar 255
AccessUserAddressIsDefault bit 1
AccessUserAddressExported datetime 8
AccessUserAddressPhoneBusiness nvarchar 255
AccessUserAddressDefaultAddressCustomFields bit 1
AccessUserAddressCountryCode nvarchar 2