Page 1 of 1

Order Items API returning error when order has both shipping and non-shipping items

Posted: Mon Jul 22, 2019 12:23 pm
by gwalliman
We noticed this behavior when trying to call the /api/Orders/Items endpoint. This endpoint works fine when the order has only items that can be shipped (physical products, etc.) but when the order has both shipping and non-shipping items (example: a book and a membership subscription) we get a 500 error with the message "An error has occurred."

How can we fix this? Thanks much!

Re: Order Items API returning error when order has both shipping and non-shipping items

Posted: Thu Aug 08, 2019 11:23 am
by Shopping Cart Admin
Hello,

Please try this again and then go to the error log, so you can post the real error message.

Re: Order Items API returning error when order has both shipping and non-shipping items

Posted: Thu Aug 08, 2019 3:36 pm
by gwalliman
Hello, thanks much for the response!

I'm assuming you mean the error log within the web UI at /Admin/Help/ErrorLog.aspx? This log does not seem to display any errors thrown by the API failure. Is there another error log (perhaps an on-server log) that might show these errors?

Re: Order Items API returning error when order has both shipping and non-shipping items

Posted: Sun Aug 25, 2019 1:17 pm
by gwalliman
It's been over two weeks - could I please get a response?

Re: Order Items API returning error when order has both shipping and non-shipping items

Posted: Mon Aug 26, 2019 1:52 pm
by nadeem
Hello,

You need to check the log file inside App_Data i.e. Website/App_Data/app.log file to find the actual error. I just reviewed the API code that is originating the error has a null reference exception. You can fix the error if you have CommerceBuilder.WebApi source code.

Open the Controllers/OrdersControllers.cs file, locate the following line of code:

Code: Select all

OrderShipmentId = item.OrderShipment.Id,
and replace with

Code: Select all

OrderShipmentId = item.OrderShipment == null ? 0 : item.OrderShipment.Id,
There are two locations that need the above update in the same controller, one is under GetItemsByOrderId(int id) action method and the other is under GetItemsByOrderNumber(int orderNumber)
After making the above change, compile the CommerceBuilder.WebApi project and then compile the website to reflect this update.