Commerce versions 10: When copying IOrderAddress to _orderGroup.GetFirstShipment().ShippingAddress metafields dosen't get carried over


When doing _orderGroup.GetFirstShipment().ShippingAddress = address; metafields are not getting carried over. Do we need to do this manually with a foreach loop on address.Properties?

May 03, 2017 23:48

Hi Sapna,

I don't think all properties need to be loop for setting an OrderAddress to Shipping Address, you're doing correctly. I just don't know your whole code.

Could you try this:

var orderRepository = ServiceLocator.Current.GetInstance();
var cart = orderRepository.LoadOrCreateCart(customerId, _defaultName);
var address = cart.CreateOrderAddress();
address.Id = "FakeOrderAddressID"; // This is required.
address.FirstName = "Son";
address.LastName= "Do";
address.Line1 = "2134 Aurelle Rd, Strong, AR, 71765";
// ...

address.Properties["YourMetaFieldName"] = "sample property value";
cart.GetFirstShipment().ShippingAddress = address;
var _cartLink = orderRepository.Save(cart);

And this is the result:

For working with Cart, we could refer to this document

Hope this helps,

/Son Do

Edited, May 04, 2017 6:01
<p>Hi Son! I believe we are doing something pretty similar to what you mentioned above. But when I debug I don't see any values. I don't see any value in data base either.</p> <p>I tried your exact code as well. But the metafields dont get carried over. Our metafield is a boolean. Do &nbsp;you think that can cause any issue?</p> <p>Here is my code:</p> <p>var shipment = cart.GetFirstShipment();<br /> if (address != null)<br />{</p> <p>address.Id = Constants.Order.ShippingAddressName;<br /> address.Email = Authentication.GetOrderEmail(cart);<br /> shipment.ShippingAddress = address;</p> <p>}</p> <p>var orderService = ServiceLocator.Current.GetInstance&lt;IOrderRepository&gt;();<br /> orderService.Save(cart);</p>
May 04, 2017 18:04

I think address might be root cause this issue. It need to be created this way:

var address = cart.CreateOrderAddress();

Could you show us the code how to create address? And you're using SerializableCart mode or Legacy?

Edited, May 05, 2017 3:56
<p>I think we are using legacy code. How do I verify though? I don't know what to look for to confirm this. Sorry!</p> <p>This is the method thats been called always to get the address :</p> <p>public IOrderAddress ToOrderAddress(ICart cart, CustomerAddress addr)<br /> {<br /> IOrderAddress address = cart.CreateOrderAddress();<br /> if (addr != null)<br /> {<br /> address.Id = addr.Name;<br /> address.FirstName = addr.FirstName;<br /> address.LastName = addr.LastName;<br /> address.Line1 = addr.Line1;<br /> address.Line2 = addr.Line2;<br /> address.PostalCode = addr.PostalCode;<br /> address.City = addr.City;<br /> address.CountryCode = addr.CountryCode;<br /> address.CountryName = getCountryName(addr.CountryCode);<br /> address.RegionCode = addr.RegionCode;<br /> address.RegionName = addr.RegionName;<br /> address.Organization = addr.OrganizationName;<br /> address.DaytimePhoneNumber = addr.DaytimePhoneNumber;<br /> address.Properties["LastModifiedDate"] = addr.Properties["LastModifiedDate"];<br /> address.Properties["IsValidated"] = addr.Properties["IsValidated"];<br /> address.Properties["UserChoosetoOverrideValidation"] = addr.Properties["UserChoosetoOverrideValidation"];</p> <p>}</p> <p>return address;<br /> }</p>
May 05, 2017 18:05

I don't find any special thing with those codes. It should work as expected :-?

  • Is there anyway CustomerAddress addr is null?
  • Did you add LastModifiedDate, IsValidated, UserChoosetoOverrideValidation metafield to OrderFormAddress in Commerce Manager?
  • And could you print your db with query I did in your DB
May 05, 2017 19:58

Yes, we have done all that. And addr is not null. 

Please try below link for screen shot

May 05, 2017 20:23

Ah, I remember we have a bug for this issue before

and it was fixed. Could you upgrade to latest Commerce version and try again.

May 07, 2017 11:46
* 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.