Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create method to transfer all commerce data from one user to another #2801

Merged
merged 18 commits into from Jun 29, 2022

Conversation

timkelty
Copy link
Collaborator

@timkelty timkelty commented May 4, 2022

This PR adds the ability to move all commerce data related to a user, to another user.

  • Added craft\commerce\services\Customers::moveCustomerDataToCustomer().
  • Added the commerce/move-data command which calls the service method.

@linear
Copy link

linear bot commented May 4, 2022

DSG-127 Create method to transfer all commerce data from one user to another

My use case:

  • for Craft Console, we are:
    • converting existing developers users to non-credentialed "organization" accounts
    • creating new "organization admin" accounts (email/pass cloned from developersaccount)

So, we need to transfer any commerce data from the original users to the newly created ones.

@lukeholder lukeholder changed the base branch from develop to 4.1 May 17, 2022 01:19
@timkelty
Copy link
Collaborator Author

timkelty commented Jun 2, 2022

@lukeholder tried this on craftnet and got:

Exception 'yii\db\IntegrityException' with message 'SQLSTATE[23505]: Unique violation: 7 ERROR:  duplicate key value violates unique constraint "idx_lcygpysjfngcjzeomcnmwjzgajkqsxheuxfz"
DETAIL:  Key ("customerId")=(783510) already exists.
The SQL being executed was: UPDATE "commerce_customers" SET "customerId"=783510 WHERE "customerId"=19585'

in /var/www/html/vendor/yiisoft/yii2/db/Schema.php:676

Error Info:
Array
(
    [0] => 23505
    [1] => 7
    [2] => ERROR:  duplicate key value violates unique constraint "idx_lcygpysjfngcjzeomcnmwjzgajkqsxheuxfz"
DETAIL:  Key ("customerId")=(783510) already exists.
)

Caused by: Exception 'PDOException' with message 'SQLSTATE[23505]: Unique violation: 7 ERROR:  duplicate key value violates unique constraint "idx_lcygpysjfngcjzeomcnmwjzgajkqsxheuxfz"
DETAIL:  Key ("customerId")=(783510) already exists.'

in /var/www/html/vendor/yiisoft/yii2/db/Command.php:1302

Stack trace:
#0 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1302): PDOStatement->execute()
#1 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1102): yii\db\Command->internalExecute('UPDATE "commerc...')
#2 /var/www/html/packages/craftcms/src/helpers/Db.php(1043): yii\db\Command->execute()
#3 /var/www/html/packages/commerce/src/services/Customers.php(197): craft\helpers\Db::update('{{%commerce_cus...', Array, Array, Array, false)
#4 /var/www/html/src/console/controllers/OrgsController.php(102): craft\commerce\services\Customers->moveCustomerDataToCustomer(Object(craft\elements\User), Object(craft\elements\User))
#5 /var/www/html/vendor/illuminate/collections/Traits/EnumeratesValues.php(263): craftnet\console\controllers\OrgsController->craftnet\console\controllers\{closure}(Object(craft\elements\User), 0)
#6 /var/www/html/src/console/controllers/OrgsController.php(114): Illuminate\Support\Collection->each(Object(Closure))
#7 [internal function]: craftnet\console\controllers\OrgsController->actionConvert()
#8 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#9 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#10 /var/www/html/vendor/yiisoft/yii2/console/Controller.php(182): yii\base\Controller->runAction('convert', Array)
#11 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\console\Controller->runAction('convert', Array)
#12 /var/www/html/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('craftnet/orgs/c...', Array)
#13 /var/www/html/packages/craftcms/src/console/Application.php(90): yii\console\Application->runAction('craftnet/orgs/c...', Array)
#14 /var/www/html/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('craftnet/orgs/c...', Array)
#15 /var/www/html/packages/craftcms/src/console/Application.php(121): yii\console\Application->handleRequest(Object(craft\console\Request))
#16 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
#17 /var/www/html/craft(13): yii\base\Application->run()
#18 {main}

@timkelty timkelty force-pushed the feature/dsg-127-create-method-to-transfer-all-commerce branch from 0b8f60f to 78c92bb Compare June 14, 2022 20:41
… of github.com:craftcms/commerce into feature/dsg-127-create-method-to-transfer-all-commerce
`Customers::moveCustomerData()` and `commerce/move-customer-data`
@lukeholder
Copy link
Member

lukeholder commented Jun 29, 2022

@timkelty renamed to

Customers::transferCustomerData() and commerce/transfer-customer-data

Console command now accepts emails and usernames, not user IDs

@lukeholder lukeholder marked this pull request as ready for review June 29, 2022 09:27
@lukeholder lukeholder requested a review from a team as a code owner June 29, 2022 09:27
@lukeholder lukeholder merged commit e0c3ac6 into 4.1 Jun 29, 2022
@lukeholder lukeholder deleted the feature/dsg-127-create-method-to-transfer-all-commerce branch June 29, 2022 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants