Shopware Tricks
From etlam.eu Tech Wiki
DISCLAMER: these "tricks" are provided "as is", without warranty of any kind. These may break your shop, test them thoroughly before using them. You have been warned.
Unless noted otherwise, everything applies to or has been tested on Shopware 6.6
Move orders to a different account
This query moves all orders made by a (guest) user to a different user.
Replace <TARGET CUSTOMER ID> with the customer number of the target account. Replace <GUEST CUSTOMER ID> with the customer number of the guest account.
UPDATE `order_customer`
SET `customer_id` = (SELECT `id` FROM `customer` WHERE `customer_number` = '<TARGET CUSTOMER ID>' ORDER BY `id` DESC LIMIT 1), , `customer_number` = '<TARGET CUSTOMER ID>'
WHERE `order_customer`.`customer_id` = (SELECT `id` FROM `customer` WHERE `customer_number` = '<GUEST CUSTOMER ID>' ORDER BY `id` DESC LIMIT 1);
If you only want to move one order, this query does the trick. Replace <TARGET CUSTOMER ID> with the customer number of the target account. Replace <ORDER ID> with the order number.
UPDATE `order_customer`
SET `customer_id` = (SELECT `id` FROM `customer` WHERE `customer_number` = '<TARGET CUSTOMER ID>' ORDER BY `id` DESC LIMIT 1), `customer_number` = '<TARGET CUSTOMER ID>'
WHERE `order_customer`.`order_id` = (SELECT `id` FROM `order` WHERE `order_number` = '10016' ORDER BY `<ORDER ID>` DESC LIMIT 1);