Saikios
Saikios

Reputation: 3711

Update Status of an Order on Prestashop using Webservices

I just want to update the current_state of an order,

<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
    <order>
        <id>1</id>
        <current_state>1</current_state>

    </order>
</prestashop>

But the prestashop is asking me for all the mandatory fields of a Post when I use the put,

I tried using the exact same information than the put but it's loosing the total ammounts when I do the put,

Is there something wrong on prestashop architecture?

Upvotes: 1

Views: 2674

Answers (3)

PrestaAlba
PrestaAlba

Reputation: 689

You must download all order information with get request. Then modify current_state field before make put request to update values. You can not just send only desired fields to update.

Check examples here: Prestashop Webservices Data Modification

Upvotes: 1

Cristian Scheel
Cristian Scheel

Reputation: 878

Complementing the correct answer, in fact for update the current_state you can only send this value and instead of use a put you can use a patch.

So you dont need to send all the body of the order.

url = f"{SHOP_URL}/api/orders/{order_id}?output_format=JSON"
auth_header = {
    'Authorization': 'Basic ' + get_token()
}
xml_body = f"""<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
    <order>
        <id>{order_id}</id>
        <current_state>6</current_state>
    </order>
</prestashop>"""
response = requests.patch(url, headers=auth_header, data=xml_body)

Upvotes: 0

Knowband Plugins
Knowband Plugins

Reputation: 1317

You can call the setWsCurrentState() on the order object. This function is defined in Order.php class file.

This function takes the ID of order state you want to set for the order.

Upvotes: 0

Related Questions