Update Order Status using MySQL Queries in Magento 2

0
5238
Update Order Status using MySQL Queries in Magento 2
Update Order Status using MySQL Queries in Magento 2

In this post, I will show you an easy way to update order status using MySQL queries in Magento 2.

Normally, in Magento, if you cannot change order status in a free way, you must take some corresponding actions in order to transit order from one status to another status. Let say you have a Pending order, and for some reasons, you want to change it to Complete status, then you need to do a list of actions like generating invoice, adding shipment… This is easy, but what if you want to change an order status from Complete to Processing, because you make a mistake when submit the shipment. Well, you can’t change order status backward in Magento 2.

Because of this, as a developer, you can use MySQL queries to update order status in database.

To change order status of an order, you need to update in two tables, sales_order and sales_order_grid. Below are the queries:

UPDATE sales_order SET state='complete', status='complete' WHERE increment_id = XXX;

UPDATE sales_order_grid SET status='complete' WHERE increment_id = XXX;

If you want to change many orders at once, you can use WHERE increment_id IN(...) syntax.

By using these MySQL queries, you can also avoid unnecessary actions triggering when order status changes. This is pretty much useful when you migrate data from different-type store to Magento 2.

Well, that’s how you update order status using MySQL queries in Magento 2.