Add A Guest Customer To Old Orders

Hi all, if a customer has always checked out as a guest in the past, and now decides to register. Is there a way to attach their old orders to their new registration?

We have a customer now who has ordered 3 times in the past. Today she registered an account (with the same email address) and I would like to link her past orders to her newly registered account.

Is this possible?

Thanks,

Scott.

open to /app/functionsfn.cart.php

goto fn_get_orders

Replace
if (!empty($params['user_id'])) {
$condition .= db_quote(' AND ?:orders.user_id IN (?n)', $params['user_id']);
}
with
if (!empty($params['user_id'])) {
$condition .= db_quote(' AND ?:orders.user_id IN (?n)', $params['user_id']);
$condition .= db_quote(' OR ?:orders.email = ?s', $_SESSION['cart']['user_data']['email']);
}

if (!empty($params['user_id'])) {

$condition .= db_quote(' AND ?:orders.user_id IN (?n)', $params['user_id']);
$condition .= db_quote(' OR ?:orders.email = ?s', $_SESSION['cart']['user_data']['email']);
}

This code will only work once the user is registered.

I'm pretty sure the following will work:

Go into Customers::Customers and find the user's ID (first column) and email.

Use phpadmin to Update the orders table:

update cscart_orders
set user_id = 10000
where
  user_id = 0 and email = 'THEEMAIL@WHEREVER.COM';

Change 10000 to the user's id and THEEMAIL@WHEREVER.COM to his email.

The easiest way for me is to find orders by e-mail, edit each order and assign customer account to the order there

http://prntscr.com/bpiuro

Thanks everyone. As this feature needs to be tied into a custom v.i.p. program that we have, I've asked our developer to do it.

Cheers.

A SQL query would be the most efficient way to do it. Below is NOT tested but intended to show how to do it. It should be tested on a copy of your database before executing it on any kind of live server.

UPDATE cscart_orders AS o SET o.user_id=u.user_id
INNER JOIN cscart_users AS u ON u.email = o.email
WHERE o.user_id=0

THIS HAS NOT BEEN TESTED and is for demonstration purposes only.

We've now implemented this as an action in our EZ Admin Helper addon.

If you want to do it manually, the tested solution is:

To check for how many orders will be updated use:

SELECT count(*) FROM cscart_orders AS o
INNER JOIN cscart_users AS u ON u.email=o.email
WHERE o.user_id = 0 AND u.email IS NOT NULL

And then to update the orders (if any) use:

UPDATE `cscart_orders` AS o
INNER JOIN cscart_users AS u ON o.email=u.email
SET o.user_id = u.user_id
WHERE o.user_id=0 AND u.email IS NOT NULL

Or just buy the addon and click the run-now link associated with that action! :-)

We recommend running this action on a monthly cycle and the defaults for the action are set to that.

Hi tbirnseth,

I've only got a single storefront where I don't ?think? it would matter, but shouldn't there be a 'and o.company_id = u.company_id' added to the joins in those queries?