Order addresses are useful when you manage address data retrieved from Customer Management and Order Management, since they use different models for storing data: one uses Meta Data Plus, and the other uses Business Foundation (BF).
Note: This section explains how to work with addresses using the older APIs. Episerver recommends using the abstraction APIs to manage addresses, as described in Working with addresses.
Classes in this topic are available in the following namespaces:
- Mediachase.Commerce.Orders. Contains OrderAddress, OrderGroup, Cart, and PurchaseOrder.
- Mediachase.Commerce.Customer. Contains CustomerAddress.
- Mediachase.Commerce.Customers.Profile. Contains CustomerProfile.
Key classes and files
- OrderAddress*. Contains properties of an order address.
- CustomerAddress**. Contains properties of a customer address.
- OrderGroup*. Contains the collection of order addresses.
- Cart*. Inherits from OrderGroup.
- PurchaseOrder* Inherits from OrderGroup.
- StoreHelper. Contains helper methods for converting addresses.
- CustomerProfile. Contains customer profile information, like preferred shipping and billing addresses.
- CustomerProfileWrapper. Extends and adds functionality to CustomerProfile class.
- CustomerContact**. Contains properties of contacts, like addresses, credit cards, and associated organizations.
- AddressEditModule.ascx. (CMSSite/Templates/Everything/BusinessControls/CheckoutControls/SharedModules), used in checkout by the CheckoutAddressModule.ascx (inside of CheckoutWizardModule.ascx) to create an OrderAddress.
* Metaclass from Meta Data Plus; ** BF class
How it works
- The OrderGroup.OrderAddresses property stores an order's addresses.
- This property contains an OrderAddressCollection, which contains OrderAddress instances.
- Use the OrderAddress Name property as an identifier of each address.
- Distinguish shipping and billing addresses by having different Name values.
- Addresses for a customer are stored in a similar fashion.
- The CustomerContact object for a user contains a ContactAddresses collection, which contains CustomerAddress instances.
- The CustomerContact for a user is accessible via CustomerContext.Current.GetContactForUser().
- The CustomerAddress class contains similar properties to the OrderAddress class and uses the Name property as identifiers for addresses.
- The CustomerProfileWrapper (which object for a user (accessible through SecurityContext.Current.CurrentUserProfile), contains two properties, PreferredBillingAddress and PreferredShippingAddress, which contain the name of the appropriate address.
- To convert an OrderAddress to a ContactAddress, use StoreHelper.ConvertToCustomerAddress(). To do the opposite address conversion, use the ConvertToOrderAddress() method.
Examples
Example: retrieving a customer's preferred shipping address
CustomerContact contact = CustomerContext.Current.GetContactForUser(SecurityContext.Current.CurrentUser);
CustomerProfileWrapper customerProfile = SecurityContext.Current.CurrentUserProfile as CustomerProfileWrapper;
IEnumerable addresses = contact.ContactAddresses;
foreach (CustomerAddress ca in addresses)
{
if (ca.Name == customerProfile.PreferredShippingAddress)
{
//we have the preferred shipping address
}
}
Example: retrieving a shipping address
string shippingAddressName = cart.OrderForms[0].Shipments[0].ShippingAddressId;OrderAddressCollection addresses = cart.OrderAddresses;
foreach (OrderAddress oa in addresses)
{
if (oa.Name == shippingAddressName)
{
//we have found the shipping address
}
}
Do you find this information helpful? Please log in to provide feedback.