Is it possible to merge two or more (copying customers orders and other stuff ) customer accounts?
is it possible in magento?
Is it possible to merge two or more (copying customers orders and other stuff ) customer accounts?
is it possible in magento?
There is no such backend functionality, but it must be possible by editing the database directly. I have never done this, so don't use this in a productive system, but I would propose you do:
I am typing this free, so I don't know the actual table names atm. Do you need a list, or can you find them yourself?
Cheers Simon
$keepid = $keepcustomer->getId();
$keepemail = $keepcustomer->getEmail();
$keepegroup = $keepcustomer->getGroupid();
foreach($mergeids as $id) {
$customer = Mage::getModel('customer/customer')->load($id);
$email = $customer->getEmail();
$orderCollection = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('customer_email',$email);
foreach($orderCollection as $order) {
$order->setCustomer_id($keepid);
$order->setCustomer_email($keepemail);
$order->setCustomer_group_id($keepegroup);
$order->save();
}
// $wishList = Mage::getSingleton('wishlist/wishlist')->loadByCustomer($customer);
$wcollection = Mage::getSingleton('wishlist/wishlist')->getCollection()
->addFieldToFilter('customer_id', array('eq'=>$id));
if ( count($wcollection)>0 ) {
foreach($wcollection as $wish) {
$wish->setCustomer_id($keepid);
$wish->save();
}
}
$bcollection = Mage::getSingleton('sales/billing_agreement')->getCollection()
->addFieldToFilter('customer_id', array('eq'=>$id));
if ( count($bcollection)>0 ) {
foreach($bcollection as $billing) {
$billing->setCustomer_id($keepid);
$billing->save();
}
}
$ncollection = Mage::getModel('newsletter/queue')->getCollection()
->addFieldToFilter('newsletter_sender_email', array('eq'=>$email));
if ( count($ncollection)>0 ) {
foreach($ncollection as $n) {
$n->setNewsletter_sender_email($keepemail);
$n->save();
}
}
$ncollection = Mage::getModel('newsletter/subscriber')->getCollection()
->addFieldToFilter('customer_id', array('eq'=>$id));
if ( count($ncollection)>0 ) {
foreach($ncollection as $n) {
$n->setCustomer_id($keepid);
$n->setSubscriber_email($keepemail);
$n->save();
}
}
$ncollection = Mage::getModel('newsletter/template')->getCollection()
->addFieldToFilter('template_sender_email', array('eq'=>$email));
if ( count($ncollection)>0 ) {
foreach($ncollection as $n) {
$n->setTemplate_sender_email($keepemail);
$n->save();
}
}
$dcollection = Mage::getModel('downloadable/link_purchased')->getCollection()
->addFieldToFilter('customer_id', array('eq'=>$id));
if ( count($dcollection)>0 ) {
foreach($dcollection as $d) {
$d->setCustomer_id($keepid);
$d->save();
}
}
$dcollection = Mage::getModel('sales/recurring_profile')->getCollection()
->addFieldToFilter('customer_id', array('eq'=>$id));
if ( count($dcollection)>0 ) {
foreach($dcollection as $d) {
$d->setCustomer_id($keepid);
$d->save();
}
}
$customer->delete();
}
@Guru's answer is a good answer but it's not very thorough. All of these tables need updating and any table(s) extensions have added.
EDIT: I've opened a new question on this subject.
See this answer on how to find native table name from object name in Magento 1.9 / OpenMage.
+-------------------------------+
| TABLE_NAME |
+-------------------------------+
| activity_event | <- added by other extension
| catalog_compare_item |
| customer_product | <- added by other extension
| customer_telephone_call | <- added by other extension
| downloadable_link_purchased |
| gift_message |
| log_customer |
| log_visitor_online |
| mailchimp_interest_group | <- added by Mailchimp extension
| newsletter_subscriber |
| oauth_token |
| persistent_session |
| poll_vote |
| product_alert_price |
| product_alert_stock |
| rating_option_vote |
| report_compared_product_index |
| report_viewed_product_index |
| review_detail |
| sagepaysuite_tokencard | <- added by Sagepay extension
| sales_billing_agreement |
| sales_flat_order |
| sales_flat_order_address |
| sales_flat_order_grid |
| sales_flat_quote |
| sales_flat_quote_address |
| sales_flat_shipment |
| sales_recurring_profile |
| salesrule_coupon_usage |
| salesrule_customer |
| stripe_customers | <- added by Stripe extension
| tag_relation |
| wishlist |
+-------------------------------+