November Happy Hour will be moved to Thursday December 5th.

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

Vote:
 

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?

#178186
May 03, 2017 23:48
Vote:
 

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 https://world.episerver.com/documentation/developer-guides/commerce/orders/order-manipulation/.

Hope this helps,

/Son Do

#178187
Edited, May 04, 2017 6:01
Vote:
 
<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>
#178212
May 04, 2017 18:04
Vote:
 

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?

#178222
Edited, May 05, 2017 3:56
Vote:
 
<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>
#178265
May 05, 2017 18:05
Vote:
 

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
#178267
May 05, 2017 19:58
Vote:
 

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

Please try below link for screen shot

https://www.screencast.com/t/ysO0gS43y3A

#178268
May 05, 2017 20:23
Vote:
 

Ah, I remember we have a bug for this issue before https://world.episerver.com/forum/developer-forum/Episerver-Commerce/Thread-Container/2017/3/order-address-metafields-saving-issue/

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

#178283
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.