Skip to content

Commit f5c91c2

Browse files
committed
Fixed early debounce on coupon code entry.
We also keep the incorrect code on the screen so they know what type typed wrong
1 parent 4366afb commit f5c91c2

File tree

7 files changed

+79
-33
lines changed

7 files changed

+79
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Improved product index performance by not eager-loading variants for table attributes that are already fetched via SQL joins. ([#4236](https://github.com/craftcms/commerce/issues/4236))
6+
- Fixed a bug where coupon codes would be automatically submitted too soon while entering them on order edit screens.
67

78
## 5.5.4 - 2026-02-18
89

src/web/assets/commerceui/dist/css/order.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/commerceui/dist/css/order.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/commerceui/dist/js/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/commerceui/dist/js/app.js.LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424

2525
/**!
26-
* Sortable 1.15.6
26+
* Sortable 1.15.0
2727
* @author RubaXa <[email protected]>
2828
* @author owenm <[email protected]>
2929
* @license MIT

src/web/assets/commerceui/dist/js/app.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/commerceui/src/js/order/apps/OrderMeta.vue

Lines changed: 73 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@
3131
:errors="getErrors('couponCode')[0]"
3232
>
3333
<input
34-
class="text fullwidth"
34+
ref="couponCodeInput"
35+
class="text fullwidth coupon-code-input"
36+
:class="{'coupon-code-invalid': couponCodeInvalid}"
3537
type="text"
36-
v-model="couponCode"
38+
v-model="couponCodeLocal"
39+
@focus="onCouponCodeFocus"
40+
@input="onCouponCodeInput"
41+
@blur="onCouponCodeBlur"
42+
@keyup.enter="onCouponCodeBlur"
3743
autocomplete="off"
3844
autocorrect="off"
3945
autocapitalize="off"
@@ -347,6 +353,26 @@
347353
348354
mixins: [mixins],
349355
356+
data() {
357+
return {
358+
couponCodeLocal: '',
359+
couponCodeInvalid: false,
360+
};
361+
},
362+
363+
watch: {
364+
'draft.order.couponCode': {
365+
immediate: true,
366+
handler(newValue) {
367+
// Only sync from server if we're not in an invalid state
368+
// (invalid state is managed by onCouponCodeBlur)
369+
if (!this.couponCodeInvalid) {
370+
this.couponCodeLocal = newValue || '';
371+
}
372+
},
373+
},
374+
},
375+
350376
computed: {
351377
...mapState({
352378
draft: (state) => state.draft,
@@ -380,32 +406,7 @@
380406
.catch((error) => {
381407
this.$store.dispatch('displayError', error);
382408
});
383-
}, 1000),
384-
},
385-
386-
couponCode: {
387-
get() {
388-
return this.draft.order.couponCode;
389-
},
390-
391-
set: debounce(function (value) {
392-
const draft = JSON.parse(JSON.stringify(this.draft));
393-
draft.order.couponCode = value;
394-
395-
this.recalculateOrder(draft)
396-
.then(() => {
397-
this.$store.dispatch(
398-
'displayNotice',
399-
this.$options.filters.t(
400-
'Order recalculated.',
401-
'commerce'
402-
)
403-
);
404-
})
405-
.catch((error) => {
406-
this.$store.dispatch('displayError', error);
407-
});
408-
}, 1000),
409+
}, 2000),
409410
},
410411
411412
suppressEmails: {
@@ -465,6 +466,46 @@
465466
methods: {
466467
...mapActions(['recalculateOrder']),
467468
469+
onCouponCodeFocus() {
470+
if (this.couponCodeInvalid) {
471+
this.$refs.couponCodeInput.select();
472+
}
473+
},
474+
475+
onCouponCodeInput() {
476+
this.couponCodeInvalid = false;
477+
},
478+
479+
onCouponCodeBlur() {
480+
if (this.couponCodeLocal === this.draft.order.couponCode) {
481+
return;
482+
}
483+
484+
const submittedCode = this.couponCodeLocal;
485+
const draft = JSON.parse(JSON.stringify(this.draft));
486+
draft.order.couponCode = submittedCode;
487+
488+
this.recalculateOrder(draft)
489+
.then(() => {
490+
// Check if server cleared the coupon code (invalid)
491+
if (submittedCode && !this.draft.order.couponCode) {
492+
this.couponCodeInvalid = true;
493+
} else {
494+
this.couponCodeInvalid = false;
495+
}
496+
this.$store.dispatch(
497+
'displayNotice',
498+
this.$options.filters.t(
499+
'Order recalculated.',
500+
'commerce'
501+
)
502+
);
503+
})
504+
.catch((error) => {
505+
this.$store.dispatch('displayError', error);
506+
});
507+
},
508+
468509
markAsCompleted() {
469510
if (
470511
!window.confirm(
@@ -622,4 +663,8 @@
622663
.shipping-method-handle {
623664
color: $mediumTextColor;
624665
}
666+
667+
.coupon-code-input.coupon-code-invalid {
668+
color: var(--error-color, #cf1124);
669+
}
625670
</style>

0 commit comments

Comments
 (0)