Changing the Store ID on an Order in Magento

Published by John on October 25, 2018 Under Magento

If you have ever had to change an Order in Magento 1.X, you know it isn’t a straightforward process. By default, if you ‘edit’ the order, it actually cancels the existing order and then recreates it. Also, once an order has shipped or a credit memo has been created, I think you can’t even do that. There are some plugins available that allow you to edit orders, so if you find yourself needing to do it a lot, it may be worth going with one of those. However, for most of the Magento Stores I help manage, it is a pretty rare thing, however recently, an order got placed on the wrong store on one of my clients Magento website, which uses a multi-store setup.

Rather than purchase a plugin or try to find a free one, I decided to dig into the database and see if I could change the store ID of the order manually. After a little trial and error, I was able to identify and change the store ID.

Warning: This will update ALL orders that use the {NEW_STORE_ID}, so if this is not acceptable, make sure to adjust the query to limit by order ID or some other variable.

Warning: Backup your database first and be comfortable restoring it. Also, this is without warranty. It appears to have worked for me, but use at your own risk!

Warning: Please read all warnings before continuing!

The below are the Mysql queries I ran to update the order ID. Make sure to replace {OLD_STORE_ID} and {NEW_STORE_ID} with the correct numeric store IDs, as well as {STORE_NAME}!

update sales_flat_order set store_id = {NEW_STORE_ID} where store_id = {OLD_STORE_ID};
update sales_shipping_aggregated_order set store_id = {NEW_STORE_ID} where store_id = {OLD_STORE_ID};
update sales_order_aggregated_updated set store_id = {NEW_STORE_ID} where store_id = {OLD_STORE_ID};
update sales_order_aggregated_created set store_id = {NEW_STORE_ID} where store_id = {OLD_STORE_ID};
update sales_invoiced_aggregated_order set store_id = {NEW_STORE_ID} where store_id = {OLD_STORE_ID};
update sales_flat_order_item set store_id = {NEW_STORE_ID} where store_id = {OLD_STORE_ID};

update sales_flat_order_grid set store_name = "{STORE_NAME}\{STORE_NAME}\{STORE_NAME}" where store_id = {OLD_STORE_ID};
update sales_flat_order_grid set store_id = {NEW_STORE_ID} where store_id = {OLD_STORE_ID};

No Comments |

Add a Comment