Describe your bug or feature request.
The coupon "total per customer" usage limit is inconsistent with its promotion counterpart.
At the promotion level, the "total per customer" limit is evaluated even if the order email address is unknown which means, if there's a "total per customer" configured, the promotion won't apply until the customer is known.
At the coupon level, if the customer isn't known, the condition will pass and the limit will be bypassed which looks like a bug to me. Not really sure if it was implemented like this by mistake or...
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | commerce_promotion-duplicate-coupon-discounts-3278227-24.patch | 3.01 KB | erom |
| #2 | 3278227-2-tests-only.patch | 1.25 KB | jsacksick |
| #2 | 3278227-2.patch | 2.16 KB | jsacksick |
Comments
Comment #2
jsacksick commentedComment #6
jsacksick commentedCommitted.
Comment #7
agoradesign commentedDoes that mean that coupons with a per customer limit cannot be applied anymore on the cart page (if the user is not logged in and haven't entered checkout before in the active session), but before this commit, it worked?
Comment #8
jsacksick commented@agoradesign: Yes, this behavior is inconsistent with how the promotion setting works. And it doesn't really make sense to allow a coupon that has a limit per customer to be applied if the customer is anonymous. That is a bug to me.
Comment #9
agoradesign commentedFrom a customer perspective, this is horrible though. As a consequence, I'd say, I won't show the coupon redemption form at all on the cart page in future projects anymore and wouldn't recommend this at all
If I'd get a promotion code, enter the store, add anything I want to buy to the cart, then see the coupon redemption form on the cart page, enter my code, get an error - I'd just leave the store and order nothing at all. You can't know, that you have to enter your e-mail address (in the checkout) first, in order to be able to redeem your coupon code
Comment #10
jsacksick commentedWell, that is only if you specify a usage limit per customer? Why would you specify a limit that you allow to be bypassed?
Comment #11
jsacksick commentedIt seems this behavior was implemented on purpose (See https://www.drupal.org/project/commerce/issues/2902495#comment-12847063).
However, I'm currently working on a headless site where customers are able to checkout as anonymous and we get the order email from the Payment gateway AFTER the order is placed, which means coupons that are limited per customer can be applied and they won't get "revoked" since the order is already placed.
Perhaps we need another setting to make this configurable... Perhaps I should consider reverting this until we gather more feedback from the community as this can be somehow considered as a "breaking change".
Not sure what's the best way to go with this.
Comment #14
jsacksick commentedAfter considering this a bit more, decided to revert the change until we actually figure out a new setting that basically controls whether or not anonymous users are skipping the "total per customer" limit.
We probably should add this setting at both the promotion & the coupon level.
Comment #15
rszrama commentedReviewed this a bit with Jonathan, and I think we're agreed. The behavior of these usage restrictions should be the same between Promotions and Coupons, but in order to preserve backwards compatibility and make the functionality more configurable, we propose a checkbox like:
Note that we need to revise the labels of both usage limits. For this one, it makes more sense to talk about "Limited uses per email address" since that is what's actually being checked ... "Customer" is too nebulous a concept at this point.
The idea is that when that box is checked, a coupon would still apply to an anonymous order that does not yet have an email address. However, once that order got an email address, its coupon might be invalidated / removed. There's a UX question to be considered there.
We would need to pair this with an update hook to ensure the checkbox was properly toggled across all promotions / coupons to match current behavior as well, though for new sites we'd actually want it to be consistent. 😬
Comment #16
jsacksick commented@rszrama: I've been discussing this today with one of our customers, and I'm not really sure how we should proceed with this because:
getCustomerUsageLimit())setInitialValue()method, but not really sure how scalable it is, just afraid that the update could hang.Thoughts?
Comment #17
rszrama commentedAfter discussing this with jsacksick today, he clarified how the checkbox is really independent of a particular kind of usage limit. We determined that we can solve for our customer's use case without introducing a regression or a potentially costly upgrade path by changing to a checkbox that reads:
[ ] Only customers with a known email address can apply this coupon.
This checkbox would default to FALSE, meaning there would be no required upgrade path, but in order to support its usage in scenarios where thousands of coupons are generated, we should ensure it can be set to TRUE on the CouponGenerationForm.
The name of the field can be requires_email_address with an equivalent method added to the Coupon entity.
Comment #18
jsacksick commentedhe clarified how the checkbox is really independent of a particular kind of usage limit.Well, actually, that's not entirely true.... the code does the following:
Which means, if no usage limit is configured, the coupon is available. ANd then, only if a usage limit per customer is configured and the order email is known, we evaluate the limit.
Not really sure if this means we need to come back to this again, or if we can still go with what we agreed upon.
Comment #19
rhovlandWhat about adding an error message that is displayed if the customer tries to use a coupon with this restriction telling them they need to login or enter an email address to use it?
Comment #20
mradcliffeI'm fairly confused by this issue. It seems we've got reverted commits, but the issue summary isn't clear about what's going on.
On 2.31, my experience is this:
Guest checkout with a coupon/promotion that implements usage_limit_customer is broken as the email address on the order is unknown.
This is probably because the email isn't being set on the order when the apply coupon button is pressed. It is available within
CouponRedemption::validateInlineForm()as$form_state->getValue('contact_information').To me this is pretty important functionality that is missing if an anonymous user cannot apply a coupon on checkout, and so I think having a test would be pretty important as well.
I added the Needs issue summary update and Needs tests tags.
Comment #21
jsacksick commentedThis would be an improvement, sure, but this would only work if the pane is actually filled.
What's unclear about what's initially described? The coupon customer usage limit is being ignored, when the order email isn't known, while the promotion usage limit is, evaluated (i.e if a customer usage limit is set at the promotion level, and the email isn't known, the promotion isn't going to apply).
Comment #22
erom commentedi've encountered something that i think is a bug that can be addressed by adding another configuration either on coupon or promotion level.
this is done as admin:
- create an order
- add products to cart
- added the same coupons multiple times
after doing the steps above, i noticed that the total was deducted based on how many coupons i've entered even when i've set the number of uses per customer to 1.
Comment #23
erom commentedanother one for anonymous users, what's the use of total per customer limit to 1 (or N) when they (anonymous users) can just create unlimited email and re-use the promotions/coupons anyway..?
i think the total per customer is applicable for authenticated users only.
Comment #24
erom commentedI've created a patch for it, hope this helps. thank you..
Comment #25
jsacksick commented@erom: Your patch seems to be addressing a different issue. This patch was about fixing the behavior for anonymous users which are able to use a coupon that have a customer usage limit.
For example, you set the "total per customer" field to 1 but the customer is anonymous, the limit is bypassed (ie the coupon applies).
I haven't tried to reproduce the issue your patch is attempting to solve, but this should be reported in a different issue.
Comment #26
erom commentedthank you @jsacksick, will create a report for this issue then.