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);
SET @addrID = LAST_INSERT_ID();
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...)