Try our conversational search powered by Generative AI!

[Epi1007] Avoid using concrete type Mediachase.Commerce.Orders.OrderAddress


I'm using madsstorm/CodeAnalyzers.Episerver and got the following warning:

AddressMappings.cs(45, 45): [Epi1007] Avoid using concrete type Mediachase.Commerce.Orders.OrderAddress

I'm using OrderAddress for adding contact address:



1: Is the warning something I should be bothered to? Or, is the warning obsolete and I should just skip it.

2: If the warning is proper: Why the concrete type shouldn't used? How can I add address to CustomerContact then?

Aug 05, 2022 12:10

You can use the CustomerAddress for adding adresses to a contact. OrderAdress is used in the context of orders and can be created from a CustomerAddress. So the warning probably comes from using the OrderAddres with the CustomerContact.

Aug 05, 2022 14:16

Thank you for the answer, Jeroen.

I'm also using IOrderAddress in another context: shipment.ShippingAddress.

So, what's the proper way to set shipment.ShippingAddress property? ShippingAddress is of IOrderAddress type, so I assume we should map CustomerAddress to IOrderAddress - is that right?

Aug 05, 2022 15:45

Proper way is to create an address by injecting IOrderGroupFactory and then calling CreateOrderAddress.

IOrderAddress orderAddress = orderGroupFactory.CreateOrderAddress(cart)

Map your customer address to the orderAddress object.

Then add the address to your shipment on your cart.

shipment.ShippingAddress = orderAddress
Edited, Aug 08, 2022 21:19

The general advice is to use the new Order API (i.e. interfaces, for example IOrderAddress) instead of the concrete types, like OrderAddress. But that's not an absolute rule 

I'm not quite sure why you can use an OrderAddress for contact.AddContactAddress because there is no implicit conversion between those two. You can however write a simple method to convert an IOrderAddress to a CustomerAddress, like this (untested by me)

        public static void CopyOrderAddressToCustomerAddress(IOrderAddress orderAddress, AddressEntity customerAddress)
            customerAddress.Name = orderAddress.Id;
            customerAddress.City = orderAddress.City;
            customerAddress.CountryCode = orderAddress.CountryCode;
            customerAddress.CountryName = orderAddress.CountryName;
            customerAddress.DaytimePhoneNumber = orderAddress.DaytimePhoneNumber;
            customerAddress.Email = orderAddress.Email;
            customerAddress.EveningPhoneNumber = orderAddress.EveningPhoneNumber;
            customerAddress.FirstName = orderAddress.FirstName;
            customerAddress.LastName = orderAddress.LastName;
            customerAddress.Line1 = orderAddress.Line1;
            customerAddress.Line2 = orderAddress.Line2;
            customerAddress.PostalCode = orderAddress.PostalCode;
            customerAddress.RegionName = orderAddress.RegionName;
            customerAddress.RegionCode = orderAddress.RegionCode;
            customerAddress.State = orderAddress.RegionName;

Aug 09, 2022 6:31
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.