4

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

is it possible in magento?

Teja Bhagavan Kollepara
  • 3,816
  • 5
  • 32
  • 69
Guru
  • 495
  • 1
  • 6
  • 25
  • In the Community Edition there is not such a functionality. – Andre Aus B Jun 28 '13 at 13:10
  • Thanks Andre Aus B. if we have to create this functionality programmatically, what can we do? i mean copying orders of one user to another ? or any idea about this. how can we copy orders of one user to other? Please help me in this regard. i would really be very thankful to you. – Guru Jun 28 '13 at 13:51

3 Answers3

3

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

simonthesorcerer
  • 4,813
  • 2
  • 19
  • 32
  • Thank you very much :) can you find me those tables? that would really be great. thanks a lot :) – Guru Jun 28 '13 at 19:24
2
    $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
  • 495
  • 1
  • 6
  • 25
1

@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                      |
+-------------------------------+
HenryHayes
  • 161
  • 10