Shopware Tricks: Difference between revisions

From etlam.eu Tech Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 8: Line 8:
|Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
|Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
DEALINGS IN THE SOFTWARE.
|}
|}

Revision as of 14:35, 18 November 2024

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

All code snippets may be used freely under the MIT license:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),

to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or

sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO

THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF

CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER

DEALINGS IN THE SOFTWARE.

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