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

Add an action to link sessions to customer ids. #45146

Merged
merged 3 commits into from Mar 16, 2024

Conversation

georgestephanis
Copy link
Contributor

@georgestephanis georgestephanis commented Feb 26, 2024

I'm unsure if the @since should be populated now, or if that happens when something merges -- I left it as x.x.x for now.

Unsure if this should move above the ::save_data() invocation so it can fire before the migration happens -- but to have less potential for impacts, I'm adding it after the work is done so folks could have a record of what the id changed from and to.

Submission Review Guidelines:

Changes proposed in this Pull Request:

Fires an action after a customer has logged in, and their guest session id has been deleted with its data migrated to a customer id.

This hook gives extensions the chance to connect the old session id to the customer id, if the key is being used externally.

Closes #44852

Testing

See #45146 (comment).

See #44852.

I'm unsure if the `@since` should be populated now, or if that happens when something merges -- I left it as `x.x.x` for now.

Unsure if this should move above the `::save_data()` invocation so it can fire before the migration happens -- but to have less potential for impacts, I'm adding it after the work is done so folks could have a record of what the id changed from and to.
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Feb 26, 2024
Copy link
Contributor

github-actions bot commented Feb 26, 2024

Test Results Summary

Commit SHA: a041f5c

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 37s
E2E Tests710028203535m 57s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@coreymckrill
Copy link
Collaborator

@georgestephanis could you add some testing instructions, including perhaps a code snippet that shows how the hook would be used?

@georgestephanis
Copy link
Contributor Author

Sure.

Testing instructions:

Drop this code into a mu-plugins file:

<?php

add_action( 'woocommerce_guest_session_to_user_id', function( $guest_session_id, $customer_id ) {
	wc_get_logger()->log(
		'info',
		sprintf( 'Guest with Session ID %s has logged in to Customer ID %s.', $guest_session_id, $customer_id ),
		array(
			'source' => 'test-pr-45146'
		)
	);

	// Potentially trigger other db writes or external api calls to any data stores that had been keying off the old session id.
}, 10, 2 );

Open a new incognito window and browse to your shop. Add an item to the cart, and then go to log in.

After you log in, you should be able to view a record of that conversion from Session ID to Customer ID here: /wp-admin/admin.php?page=wc-status&tab=logs

Screenshot 2024-03-11 at 11 50 19 AM Screenshot 2024-03-11 at 11 50 42 AM

@georgestephanis georgestephanis changed the title Add first draft of an action to link sessions to customer ids. Add an action to link sessions to customer ids. Mar 13, 2024
@coreymckrill coreymckrill self-requested a review March 13, 2024 19:32
Copy link
Contributor

Hi @coreymckrill,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

Copy link
Collaborator

@coreymckrill coreymckrill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you for the testing instructions and code snippet!

Unsure if this should move above the ::save_data() invocation so it can fire before the migration happens -- but to have less potential for impacts, I'm adding it after the work is done so folks could have a record of what the id changed from and to.

I think this is a good call. This way it's just a notification of something that happened instead of a place where the normal flow could get interrupted somehow.

@coreymckrill coreymckrill merged commit 3873bac into trunk Mar 16, 2024
33 checks passed
@coreymckrill coreymckrill deleted the issue/44852-session-to-login-action branch March 16, 2024 00:33
@github-actions github-actions bot added this to the 8.8.0 milestone Mar 16, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Mar 16, 2024
@alopezari alopezari added needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement]: New Action to fire before WC_Session_Handler converts a guest session to login.
3 participants