A user placed an order as guest, next time when he placing an order he is registering as customer.

I managed to manually assign his old orders to new registered account based on his email address

Now my question is:
How can I assign the old addresses to his new account?

If any of you have done that previously, please give any pointers to achieve this. Please, feel free to provide other better alternatives, if my thoughts are wrong somewhere. I'll greatly appreciate any help, thanks in advance.

  • Could you please update your question with information on how and when (which events, controllers, etc...) you have added code to assign the old orders to the new account? Maybe someone knows how to add code there for the addresses...
    – 7ochem
    Commented May 13, 2015 at 8:04
  • Hi , i am using onepagecheckout , when the user clicks on checkout , i am checking for his email in sales_flat_order for orders , assigning them to new customer account and updating guest customer status to 'NO'
    – Sree
    Commented May 13, 2015 at 8:14
  • So you're doing this manually?
    – 7ochem
    Commented May 13, 2015 at 8:14
  • yes , i am because magento don't do that automatically
    – Sree
    Commented May 13, 2015 at 8:22
  • please look on that magento.stackexchange.com/questions/62479/guest-to-customer/…
    – Amit Bera
    Commented May 13, 2015 at 10:09

2 Answers 2


I solved it like this

$orders = Mage::getModel('sales/order')->getCollection()
    ->addFieldToFilter('customer_email', $_orderEmail);

$i = 1;
foreach ($orders as $sorder) {
    $bAddress = $sorder->getBillingAddress();
    $bAddressData = $bAddress->getData();
    $cbAddress = Mage::getModel("customer/address");

Old user is registered user

You should search the table customer_entity by email address. Now write down the old entity_id and the new entity_id (= 'customer ID').

Go to the table customer_address_entity and search for the old 'customer ID' you've written down in the column parent_id. Now edit the records found and change the parent_id from the old 'customer ID' to the new one.

Old user was a guest

If the old account was a guest checkout, then you'll need to get the address data from sales_flat_order_address and put it into the customer_address_entity* tables.

You could do this by running this SQL:

SET @orderID=123; /* The order's `entity_id` */
SET @custID=123; /* Your new `customer_entity`'s `entity_id` */

/* Start with billing address: */
INSERT INTO `customer_address_entity` (`entity_type_id`, `parent_id`) VALUES (2, @custID);
INSERT INTO `customer_address_entity_int` (`entity_type_id`, `attribute_id`, `entity_id`, `value`) SELECT 2, 29, @addrID, `region_id` FROM `sales_flat_order_address` WHERE `parent_id` = @orderID AND `address_type` = 'billing';
INSERT INTO `customer_address_entity_text` (`entity_type_id`, `attribute_id`, `entity_id`, `value`) SELECT 2, 25, @addrID, `street` FROM `sales_flat_order_address` WHERE `parent_id` = @orderID AND `address_type` = 'billing';

You can repeat this for shipping address by replacing 'billing' for 'shipping' in the WHERE clause.

The new customer already has a default billing and shipping address set, but you can replace them with the ones from the guest by (for billing):

REPLACE INTO `customer_entity_int` SET `value` = @addrID WHERE `entity_type_id` = 1 AND `attribute_id` = 13 AND `customer_id` = @custID;

Repeat this for shipping address with ```attribute_id` = 14``.

You could also add more attributes to be added (see SELECT * FROM `eav_attribute` WHERE `entity_type_id` = 2, for example company, middlename, fax, suffix, etc...)

  • there is no record in customer_entity if the user placed an order as guest
    – Sree
    Commented May 13, 2015 at 8:49
  • I have updated my answer
    – 7ochem
    Commented May 13, 2015 at 9:30
  • @Sree did this work out for you?
    – 7ochem
    Commented May 18, 2015 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.