Link a sales order to an existing customer account in magento

I want to associate a guest order with an existing Magento account. Does anyone know which fields change tables to accomplish this?

Maybe easier?

+4
source share
6 answers

If you are in Magento> = 1.4.1, you can run this in your database:

UPDATE sales_flat_order SET customer_id = YOUR_CUSTOMER_ID_HERE WHERE entity_id = YOUR_ORDER_ID_HERE AND customer_id IS NULL 

You will also need to update the grid table:

 UPDATE sales_flat_order_grid SET customer_id = YOUR_CUSTOMER_ID_HERE WHERE entity_id = YOUR_ORDER_ID_HERE AND customer_id IS NULL 
+5
source

It also seems to work.

 $order_id = 5; // Your Order ID $customer_id = 7; //Customer ID $_order = Mage::getModel('sales/order')->load($order_id); if($_order->getCustomerId() == NULL){ $_order->setCustomerId($customer_id); $_order->save(); } 
+7
source

Since it is easier to get increment_id from the order from the backend than the object identifier, I prefer to use the following two queries:

 UPDATE sales_flat_order SET customer_id = YOUR_CUSTOMER_ID_HERE, customer_is_guest=0, customer_group_id = YOUR_CUSTOMER_GROUP_ID_HERE WHERE increment_id = YOUR_INCREMENT_ID_HERE AND customer_id IS NULL UPDATE sales_flat_order_grid SET customer_id = YOUR_CUSTOMER_ID_HERE, WHERE increment_id = YOUR_INCREMENT_ID_HERE AND customer_id IS NULL 
+2
source

I use magento 1.9.0.1, and I use to change the following information:
For the table sales_flat_order :
=> change customer_id from NULL to new customer_id
=> customer_is_guest to 0 .

Also for the sales_flat_order_grid table:
=> change customer_id from NULL to new customer_id

After two requests, the following task will be performed:

 UPDATE sales_flat_order SET customer_id = (Your_Customer_ID), customer_is_guest=0 WHERE entity_id = Your_Order_ID_HERE AND customer_id IS NULL UPDATE sales_flat_order_grid SET customer_id = Your_Customer_ID WHERE entity_id = Your_Order_ID AND customer_id IS NULL 
0
source

To expand on what is published by RS:

If you want the admin screen to display which group the member is in, you need a few more lines:

 $customer_id = xxxx; //Customer ID $order_increment_id = xxxxxxxxx; //Admin order increment id $_order = Mage::getModel('sales/order')->loadByIncrementId($order_increment_id); if($_order->getCustomerId() == NULL){ $_order->setCustomerId($customer_id); } if($_order->getCustomerIsGuest() == "1"){ $_order->setCustomerIsGuest(0); } if($_order->getCustomerGroupId() == "0"){ $_order->setCustomerGroupId(1); } $_order->save(); 
0
source

You can use http://www.mlx-store.com/magento-extensions/sales/convert-guest-to-user.html to convert a guest user check into a user registry.


0
source

All Articles