It’s going to happen when you run an E-Commerce website – a user who has an account checkouts while is a guest, contacts you and wants the two to be associated. Yeah, extra work for you!
In Magento, there isn’t a default feature that allows you to associate these two together. (Bad news, I know). BUT, it can be done. {insert asterisk here}
Contents
Solution Options
There are two ways to approach this:
- Install an extension
- Manually edit the database
Associate Customers Order With Account Via a Magento Extension
I know extensions are out there for this, but I have not personally used one and thus will not endorse, recommend, or even link one here for you. But a bit of effort should put you in the right direction.
Update January 5th, 2016
While I stated previously that I didn’t have an endorsement for a Magento Extension for linking a customer to an order through the Magento Admin, I am now endorsing an extension. I feel confident endorsing it because I wrote it. Yes, it’s a shameless plug. But it’s a free extension, so really it’s ok, right?
Magento Extension to Link a Customer to a Guest Order
The PromInc Magento Extension for linking customers and orders is available via Github and will require a manual installation as opposed to using Magento Connect. Feel free to download the code to add to your own Magento install. Installation and usage instructions are also documented on Github.
Download Magento Link Customer to Order Extension via Github →
Associate Customers Order With Account Via Database
What I will share with you however is how to make this correction manually in the database. To do this however, you need database access to your Magento site via either PHP MyAdmin, a 3rd party database tool like MySql Workbench, NovaBench, etc., or command line access.
NOTE: If you were completely lost by that last sentence, I’m assuming you are not a developer and/or a database admin, and this is where you would be best to turn and walk away from this post. :) I’m not trying to be rude but more honest. The setup for those tools requires configuration from your webhost, and the proper knowledge to know how to utilize these tools. Playing in the database isn’t something a novice should be doing – you can create a lot of undesirable results in there if you don’t know what you are doing.
Ok, for those of you that are still reading and understanding, here is the solution you are looking for. I know this solution works for Magento version 1.4.1 and greater.
You will need to know the following information:
- The Customers’ ID (customer_id)
- The easiest way to find the Customer ID is to view the customer in the Magento Admin and look at the URL for that customer in the address bar – the Customer ID is the number at the end of the URL.
https://www.yoursite.com/index.php/guru/customer/edit/id/200490/
- The easiest way to find the Customer ID is to view the customer in the Magento Admin and look at the URL for that customer in the address bar – the Customer ID is the number at the end of the URL.
- The Order ID (entity_id)
- NOTE: This is the Database entity ID, NOT the Order ID that you use on your invoices.
- The easiest way to find the Order ID is to open the order in the Magento Admin and look at the URL for that order in the address bar- Order ID it is the number at the end of the URL.
https://www.yoursite.com/index.php/guru/sales_order/view/order_id/291855/
There are two tables in the Magento Database that need to be updated:
- sales_flat_order
- sales_flat_order_grid
- NOTE: I believe this table is only used for the Magento Admin
If you are using a GUI based database editing tool like MySQL Workbench, you simply need to edit the Order ID entry in the two tables listed above, setting the customer_id field to the Customer ID found above.
If you prefer to do this via a SQL script, you can use the following two scripts, replacing CUSTOMER ID and Order ID with the appropriate info found above.
1 2 3 | UPDATE sales_flat_order SET customer_id = CUSTOMER ID, customer_is_guest = 0 WHERE entity_id = Order ID AND customer_id IS NULL |
1 2 3 | UPDATE sales_flat_order_grid SET customer_id = CUSTOMER ID WHERE entity_id = Order ID AND customer_id IS NULL |
1 2 3 | UPDATE sales_flat_order_address SET customer_id = CUSTOMER ID WHERE parent_id = Order ID AND customer_id IS NULL |