Try our conversational search powered by Generative AI!

Problem creating warehouses (commerce)

Vote:
 

Hello

I'm trying to create a warehouse using:

warehouseRepository.Save(new Mediachase.Commerce.Inventory.Warehouse() {
Code = "123foo",
Name = "foo",
ApplicationId = Mediachase.Commerce.Core.AppContext.Current.ApplicationId
});

However, all I'm getting is a NullReferenceException coming from the Mediachase-dll. What could be wrong? Is this a bug?

As a side note: what is the ApplicationId-field used for in this context?

Thanks!

-Emil (new to EPiServer)

(The same happens when using the example SaveWarehouse() taken from: http://world.episerver.com/Documentation/Items/Developers-Guide/EPiServer-Commerce/75/Warehouses-and-inventories/Warehouses-and-inventories-examples/)

#88501
Jul 15, 2014 12:51
Vote:
 

Apparently, and not documented, the ContactInformation property is required. So, I provided this, and the following exception now occurs:

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
The data for table-valued parameter "@Warehouse" doesn't conform to the table type of the parameter.
The statement has been terminated.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
The data for table-valued parameter "@Warehouse" doesn't conform to the table type of the parameter.
The statement has been terminated.

Must be a bug or the result of an EPiServer upgrade?

#88502
Edited, Jul 15, 2014 13:08
Vote:
 

You need to provide both created date and modified date when you create Warehouses programatically.

var warehouse = new Warehouse()
                {
                    ApplicationId = AppContext.Current.ApplicationId,
                    ContactInformation = new WarehouseContactInformation(),
                    Code = "UniqueCode",
                    SortOrder = warehouseRepository.List().Count(),
                    Created = DateTime.Now,
                    Modified = DateTime.Now,
                    Name = "Name"
                    //IsActive = true,
                    //IsPrimary = true,
                    //IsFulfillmentCenter = true,
                    //IsPickupLocation = true,
                    //IsDeliveryLocation = true
                };
            warehouseRepository.Save(warehouse);
#88504
Jul 15, 2014 13:30
Vote:
 

Thanks! :)

#88506
Jul 15, 2014 13:35
Vote:
 

Thanks for the solution.

Has still not been fixed in the latest version. The documentation should be updated atleast.

Kind Regards

Sandeep 

#116180
Jan 26, 2015 12:39
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.