Merge magento customers
Is there a way to merge customer accounts in Magento? I have a customer who's email got corrupted (or so they say) so they created a new account. I'd like to be able to merge the history of the 开发者_运维百科old customer into the new. Is this possible?
Assuming you have permission to create a MySQL stored routine and you have the information_schema database at your disposal, the following code will merge customers. Note that after creating the routine, you'll need to run it with the entity_id's of the customers as the parameters.
drop procedure if exists merge_customers;
delimiter //
create procedure merge_customers(
id1 int unsigned, -- the customer to keep
id2 int unsigned) -- the record to delete
begin
declare done int default false;
declare tbl_name, col_name varchar(255);
declare c cursor for
select table_name, column_name
from information_schema.key_column_usage
where table_schema = database()
and referenced_table_name = 'customer_entity'
and referenced_column_name = 'entity_id';
declare continue handler for not found set done = true;
open c;
read_loop: loop
fetch c into tbl_name, col_name;
if done then
leave read_loop;
end if;
set @str = concat(
'UPDATE IGNORE ', tbl_name,
' SET ', col_name, ' = ', id1,
' WHERE ', col_name, ' = ', id2
);
prepare stmt from @str;
execute stmt;
deallocate prepare stmt;
end loop;
close c;
delete from customer_entity where entity_id = id2;
end//
delimiter;
You could refund the orders of one account (which doesn't actually refund any charges) and submit identical ones under the other account using, say, the Check payment method (which doesn't actually make any charges). That way you have a paper trail of activity which wouldn't happen if you altered the database directly.
Also, ask yourself could this person be up to no good? How certain are you they are who they say they are? Simply knowing their pet's name or whichever secret question only proves they have seen the first person's facebook page. What does it even mean for an email to get "corrupted"?
I'm looking for the same thing. Definitely a needed extension.
I currently change the Customer_ID
manually in phpMyAdmin in both tables sales_flat_order
& sales_flat_order_grid
. You can find the customer ID in your magento Admin, second column in the customers section.
But it is VERY time consuming, it would be so great if someone could write a module, I'd pay for it.
精彩评论