Apply discounts on guest carts when max_uses_per_user is set#2470
Draft
glennjacobs wants to merge 1 commit into
Draft
Apply discounts on guest carts when max_uses_per_user is set#2470glennjacobs wants to merge 1 commit into
glennjacobs wants to merge 1 commit into
Conversation
checkDiscountConditions() short-circuited validMaxUses to false on any cart without a user the moment max_uses_per_user was set, which meant guest carts saw the coupon "applied" but got zero discount. The per-user limit can only be enforced when a user is known, so only run the check in that case and otherwise leave the existing validMaxUses value alone. Fixes #2442
Contributor
|
Does this mean that the discount can be used indefinitely by a non-logged in user? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AbstractDiscountType::checkDiscountConditions()now only runs the per-user usage check when the cart actually has a user. Guest carts withmax_uses_per_userset no longer silently fail the condition.Why
The old condition was:
If the cart had no user attached (guest checkout, or anonymous cart pre-login),
$cart->userwasnull, so$validMaxUsesbecamefalseand the discount was filtered out — but only at calculation time, after the coupon code had already been accepted onto the cart. From the customer's point of view the coupon "worked" but their total never changed. This is exactly what #2442 reported.A per-user limit only makes sense when a user is known, so the new condition skips the check entirely for guest carts and preserves whatever
$validMaxUseswas already set to:Logged-in users still hit the limit correctly — the third test asserts that an attached usage row blocks reuse.
Fixes #2442.
Test plan
vendor/bin/pest --testsuite=core— 506 passingmax_uses_per_user = 1on a guest cart → discount applies to total