-
Notifications
You must be signed in to change notification settings - Fork 219
Validate coupon usage against customer id AND emails #11860
Conversation
49f98c8
to
376116a
Compare
The release ZIP for this PR is accessible via:
Script Dependencies ReportThere is no changed script dependency between this branch and trunk. This comment was automatically generated by the TypeScript Errors Report
🎉 🎉 This PR does not introduce new TS errors. |
Size Change: 0 B Total Size: 1.61 MB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Test cases passed
✅ I fixed an issue with the checking of user email as well as billing email. New test case added, as well as updated the test cases for the notice on removal (which I changed to show why the coupon was removed)
✅ Code looks good.
This needs a second reviewer because I pushed some changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests work for me code looks good. The db query looks fine as well, we're escaping each value before using it in the query so I'm happy with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good and all testing steps checked out.
I also tried logged out vs logged out (new session) with same billing email.
Approving 👍🏼
* validate coupon usage against user and email * add checks for logged out user * change to direct array call * fix the query * fix the query * fix arrays * fixe how id is fetched * Make function private * use implode instead of join * coupon shouldnt be a pointer * move ignore statement * add comment about tentative usage * Update src/StoreApi/Utilities/OrderController.php Co-authored-by: Mike Jolley <[email protected]> * better validation for user data * remove unused variable * bail early if we dont have limits * add empty line after function --------- Co-authored-by: Mike Jolley <[email protected]>
* validate coupon usage against user and email * add checks for logged out user * change to direct array call * fix the query * fix the query * fix arrays * fixe how id is fetched * Make function private * use implode instead of join * coupon shouldnt be a pointer * move ignore statement * add comment about tentative usage * Update src/StoreApi/Utilities/OrderController.php Co-authored-by: Mike Jolley <[email protected]> * better validation for user data * remove unused variable * bail early if we dont have limits * add empty line after function --------- Co-authored-by: Mike Jolley <[email protected]>
* validate coupon usage against user and email * add checks for logged out user * change to direct array call * fix the query * fix the query * fix arrays * fixe how id is fetched * Make function private * use implode instead of join * coupon shouldnt be a pointer * move ignore statement * add comment about tentative usage * Update src/StoreApi/Utilities/OrderController.php Co-authored-by: Mike Jolley <[email protected]> * better validation for user data * remove unused variable * bail early if we dont have limits * add empty line after function --------- Co-authored-by: Mike Jolley <[email protected]>
* validate coupon usage against user and email * add checks for logged out user * change to direct array call * fix the query * fix the query * fix arrays * fixe how id is fetched * Make function private * use implode instead of join * coupon shouldnt be a pointer * move ignore statement * add comment about tentative usage * Update src/StoreApi/Utilities/OrderController.php Co-authored-by: Mike Jolley <[email protected]> * better validation for user data * remove unused variable * bail early if we dont have limits * add empty line after function --------- Co-authored-by: Mike Jolley <[email protected]>
* Updated changelog and added testing instructions * Updated changelog. * Updated versions. * Updated tested up to * Updated tested up to * Uploaded testing zip * Removed #11287 from testing instructions * Added testing instructions and changelog for #11858 * Updated testing zip * Testing instructions for #11862 and #11860 * Updated testing zip * New testing zip with #11872 🍒 * Updated versions to 11.7.0-dev * Updated composer.lock
WooCommerce would register coupon usage based on 2 elements, a user id if the customer has one, or the billing email.
There was an edge case in which a coupon can be used twice, once logged in with user id, and once logged out with billing email.
For the purpose of this fix, we consider emails to belong to a single user, so even as guest, it can't be used.
So in this PR, I check the coupon usage against a customer id, their billing email, and the account email (if those last 2 differ).
For a logged out customer, I first check if the email belongs to an existing user, and check its usage as well, as well as the billing email usage.
Fixes #11850
Testing Instructions
From logged in to logged out
User email vs billing email
From logged out to logged in
General regression testing
WooCommerce Visibility
Required:
Checklist
Required:
[type]
label or a[skip-changelog]
label.Changelog