Reinstate Magento order status after upgrade

Recently I upgraded a Magento store from to

Magento has changed order tables from key-value type to flat structure in, which caused a big problem for my upgrade – all orders lost their status and state value.

I have not discovered what exact reason made it happen, but I know it is my store specific, because I have other stores successfully upgraded from 1.3 to without any problems.

Just in case you had the same issue, you can run this mysql query code to reinstate Magento order status(and state as well).

UPDATE magento_sales_flat_order AS o
INNER JOIN (SELECT s1.parent_id, s1.status, c.state
 FROM magento_sales_flat_order_status_history s1
 SELECT parent_id, MAX(entity_id) AS entity_id
 FROM magento_sales_flat_order_status_history
 GROUP BY parent_id) AS s2
 ON s1.parent_id = s2.parent_id AND s1.entity_id = s2.entity_id
 LEFT JOIN magento_sales_order_status_state AS c
 ON s1.status = c.status
) as s3
ON o.entity_id = s3.parent_id, magento_sales_flat_order_grid AS g
SET o.status = s3.status, o.state = s3.state, g.status = s3.status
WHERE g.entity_id = s3.parent_id;

Leave a comment

Your email address will not be published. Required fields are marked *