Question

Is it possible to merge two or more (copying customers orders and other stuff ) customer accounts?

is it possible in magento?

Was it helpful?

Solution

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:

  • choose one of the customers that you wnt to keep, and get its entity_id from the customer table
  • get the entity_id of the second customer, and replace it with the first entity_id in the address-tables, order-tables, wishlist- and quote-tables and (maybe) some more
  • delete the second customer

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

OTHER TIPS

    $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();

    }
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top