gourmetchef Posted April 27, 2017 Share Posted April 27, 2017 (edited) I'm using the PrestaShop REST system to update order statuses by changing the current_state field. While I can change the current_state field to certain values, other values cause the call to throw a 500 server error. After some experimentation with the Order Statuses section on the backend, I determined that the issue has to do with a property for the order status itself, specifically the checkbox which reads "Set the order as shipped.". When the old order status does not have the box checked and the new order status does have it checked (or vice versa), then transitioning between the old and new order status will throw an error. If the old and new statuses both have the same checkbox value for the "Set the order as shipped." property, then transitioning between the states will not throw an error. Any suggestions? I am using PrestaShop version: 1.6.1.12 NOTE: I understand that the shipping status cannot be set back to unshipped once it is shipped, so an error on that transition direction makes sense. But the unshipped to shipped transition should work, but isn't Edited April 27, 2017 by gourmetchef (see edit history) Link to comment Share on other sites More sharing options...
ricardolobo Posted April 28, 2017 Share Posted April 28, 2017 Can you show us the code? I use this functionality without any issues. I can change to whatever state without any issues. Link to comment Share on other sites More sharing options...
gourmetchef Posted April 28, 2017 Author Share Posted April 28, 2017 (edited) Here is some C# code which replicates the issue. For context, order #4 is currently in state 2 (Payment accepted) and this is attempting to move it to state 4 (Shipped). It is failing with error code 500. Changing to state 3 (Processing in progress) works fine, as does moving it back to state 2. WebClient client = new WebClient(); client.Credentials = new NetworkCredential("REDACTED", ""); string xml = client.DownloadString("http://fibergourmet.life/api/orders/4"); XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); XmlNode state = doc.SelectSingleNode("/prestashop/order/current_state"); state.FirstChild.Value = "4"; byte[] xmlBytes = Encoding.UTF8.GetBytes(doc.InnerXml.ToString()); WebRequest req2 = WebRequest.Create("http://fibergourmet.life/api/orders"); req2.Credentials = new NetworkCredential("REDACTED", ""); req2.Method = "PUT"; Stream postStream = req2.GetRequestStream(); postStream.Write(xmlBytes, 0, xmlBytes.Length); postStream.Close(); HttpWebResponse resp2 = (HttpWebResponse)req2.GetResponse(); Console.WriteLine(resp2.StatusCode.ToString()); I've redacted our key, but if you contact me directly I'd be happy to share a temporary one so you can test it yourself. Edited April 30, 2017 by gourmetchef (see edit history) Link to comment Share on other sites More sharing options...
gourmetchef Posted May 2, 2017 Author Share Posted May 2, 2017 Ricardo, thanks for your help offline. I was able to resolve the problem after your suggestions and some perusal of the PHP example code. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now