Try our conversational search powered by Generative AI!

[11.1] Failure to set ShippingAddress on PurchaseOrder


I recently tried to create and set the ShippingAddress on a PurchaseOrder, but the ShippingAddress is always set to null.

This is the code I'm using:

var order = _orderRepository.Service.Create("Test");
order.GetFirstShipment().ShippingAddress = order.CreateOrderAddress();
order.GetFirstShipment().ShippingAddress.Id = "Shipping";

Setting Id will always fail since ShippingAddress is always null.

Isn't it possible to set a shippingAddress direktly on a PurchaseOrder? Or do I haveto create a ICart and work with that instead?

Aug 16, 2017 17:17

TL;DR: Set the ID of the IOrderAddress before setting it as ShippingAddress on the Shipment:

var shippingAddress = order.CreateOrderAddress();
shippingAddress.Id = "Shipping";
order.GetFirstShipment().ShippingAddress = shippingAddress;


The new Order API (basically using only the interfaces) is a bit quirky sometimes. The current implementation of IShipment doesn't actually "have" any orders, the Shipment.ShippingAddress is just a setter that will go to the OrderGroup.OrderAddresses and set your address there and at the same time connecting it to the shipment by 

OrderAddress.Name = Shipment.ShippingAddressId

So the OrderGroup stores and manages all the orderAddresses and links it to Shipments. But IOrderGroup (new order API) doesn't implement the addresses, I think it's meant that you add the shippingaddresses on the shipment itself, which you are doing. However the underlying connection (the code snippet above) requires the Name of the address to be set. 

But IOrderAdress.Name, instead you can set the IOrderAddress.Id to something. The current implementation of IOrderAddress.Id property looks like this:

string IOrderAddress.Id
        return this.Name;
        this.Name = value;

That Name property seem familiar? :P Again, the new API is a bit quirky, it should probably be a bit clearer that every OrderAddress needs an ID before using it (Name in background).

Aug 16, 2017 19:52
<p>That is quirky behaviour indeed. I've created the ShippingAddress directly on the Shipment before, but on a ICart; which worked as expected.</p> <p>Thanks for the explanation&nbsp;Joel, your solution worked perfectly.</p>
Aug 18, 2017 10:36

That's good finding @Joel.

I'll see if we can make the way abstraction APIs are used better.



Aug 18, 2017 13:21
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.