How to update existing warehouse from code



is there any way of updating fields like IsActive, IsFullfilmentCenter and so on from code? Or address details?

I am using Get(string code) on instance of IWarehouseRepository. 

After checking if the warehouse was not null I cannot set any of the values. Is there some kind of substitue for writable clone that is present in CMS?

Mar 08, 2018 14:17

Have you tried casting it to Warehouse?

if (_warehouseRepository.Get(warehouseCode) is Warehouse warehouse)
    warehouse.IsActive = true;

I haven't actually tried it and it is a bit ugly but as the Get function only returns IWarehouse you can't make changes to it.

Mar 08, 2018 14:30

When casting to Warehouse interface remains null. Although it looked like a valid answer it still remains open to suggestions.

Edited, Mar 08, 2018 14:35

I'm commuting now so can't check to be sure, but you can do like this:

var warehouse = new Warehouse(readOnlyWarehouse);

Then just update the warehouse and save it with IWarehouseRepository

Mar 08, 2018 18:06

I have tried that but on stepping over the actual save method VS hangs for a bit only to show me pop-up with the following message:

The debugger attempted to call a functin within the debugged process but this function call is being aborted.

Mar 09, 2018 10:01

I can confirm that code above is indeed correct. 

The error you see is a problem with the debugger in VS and has nothing to do with the API. 

Mar 09, 2018 10:07

That's right. Thank you.

Mar 09, 2018 10:28


new Warehouse(copyFrom: loadedWarehouse) won't give you a new warehouse with new/blank identifiers and the rest is copied?

It will copy everything including identifiers to get an existing entity that can be modified, not really what you would expect from a constructor or is it? surprised

Mar 09, 2018 13:53

I didn't write the code. cool

Well, it would be better if it implemented IReadonly, but we have to live with what we have today.

I'm not saying no to improvements,but in the end it always comes to priorty 

Edited, Mar 09, 2018 13:56

All change comes to priorities.

I still think someone actually looking for creating a new Warehouse by copying an existing one is in for a very rude surprise. yell

You might want to mention the constructor here:

Only example for saving a Warehouse there creates a new one with the empty constructor. It doesn't give any pointers for this modify an existing solution.

Mar 09, 2018 14:04

Fair enough. I filed a bug report for that - let's see if someone can sneak that bug fix in.

Mar 09, 2018 14:25

I updated the documentation as well - someone from Doc team (probably Bob) will review and publish it. 

Mar 09, 2018 14:30

Great! Thanks.

Mar 09, 2018 14:40

Updated doc has been published

Mar 09, 2018 17:42

It is broken. Expanding the code example link below:

Editing a warehouse

Use IWarehouseRepository.Save(IWarehouse) to edit and save a warehouse.

Note: The IWarehouse object returned from Get and List methods above IWarehouseRepository is read-only. So, to edit it, you must make a writable clone object then update it, as is.

Actually expands the code example below:

Adding a warehouse

Use IWarehouseRepository.Save(IWarehouse) to add a warehouse.

Looks like a classic copy-paste miss. laughing

Mar 12, 2018 15:46

Good spot :). But it's not a copy-paste error, editing a document with code can be quite, tricky. I will need the superior editing skill from Bob to make it right. 

Btw the bug I reported is now under review - my boss has fixed it. Take note @Erik, you don't get that a lot ;) 

Mar 12, 2018 16:36

Hopefully, the editing has now been fixed on this page -- Let us know Erik.

Mar 12, 2018 17:27

@Quan Duly noted. cool Is it a breaking changes so it will come in commerce 13 or did he sneak it into 12?

@Bob works as it should. Thanks Bob. :)

Mar 13, 2018 13:44

We are targeting Commerce 12. so if nothing strange happens then you will get the fix soon-ish 

Mar 13, 2018 13:48
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.