Skip to content

Commit 7f5ac99

Browse files
committed
AC:12170 :: Coupon code feature is not working properly in the checkout page on Magento 2.4.7
1 parent 7bfade0 commit 7f5ac99

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

app/code/Magento/SalesRule/view/frontend/web/js/view/payment/captcha.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ define([
1313
], function (defaultCaptcha, captchaList, setCouponCodeAction, cancelCouponAction, quote, ko) {
1414
'use strict';
1515

16-
var totals = quote.getTotals(),
17-
couponCode = ko.observable(null),
18-
isApplied;
19-
20-
if (totals()) {
21-
couponCode(totals()['coupon_code']);
22-
}
23-
24-
//Captcha can only be required for adding a coupon so we need to know if one was added already.
25-
var couponCodeValue = couponCode();
26-
isApplied = ko.observable(typeof couponCodeValue === 'string' && couponCodeValue.length > 0);
27-
2816
return defaultCaptcha.extend({
2917
/** @inheritdoc */
3018
initialize: function () {
3119
var self = this,
32-
currentCaptcha;
20+
currentCaptcha,
21+
totals = quote.getTotals(),
22+
couponCode = ko.observable(null),
23+
couponCodeValue,
24+
isApplied;
25+
26+
if (totals()) {
27+
couponCode(totals()['coupon_code']);
28+
}
29+
30+
// Captcha can only be required for adding a coupon so we need to know if one was added already.
31+
couponCodeValue = couponCode();
32+
isApplied = ko.observable(typeof couponCodeValue === 'string' && couponCodeValue.length > 0);
3333

3434
this._super();
3535
//Getting coupon captcha model.
@@ -66,4 +66,4 @@ define([
6666
}
6767
}
6868
});
69-
});
69+
});

app/code/Magento/SalesRule/view/frontend/web/js/view/payment/discount.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,39 @@ define([
1414
], function ($, ko, Component, quote, setCouponCodeAction, cancelCouponAction, coupon) {
1515
'use strict';
1616

17-
var totals = quote.getTotals(),
18-
couponCode = coupon.getCouponCode(),
19-
isApplied = coupon.getIsApplied();
20-
21-
if (totals()) {
22-
couponCode(totals()['coupon_code']);
23-
}
24-
25-
var couponCodeValue = couponCode();
26-
isApplied(typeof couponCodeValue === 'string' && couponCodeValue.length > 0);
27-
2817
return Component.extend({
2918
defaults: {
3019
template: 'Magento_SalesRule/payment/discount'
3120
},
32-
couponCode: couponCode,
21+
couponCode: coupon.getCouponCode(),
3322

3423
/**
3524
* Applied flag
3625
*/
37-
isApplied: isApplied,
26+
isApplied: coupon.getIsApplied(),
27+
28+
initialize: function () {
29+
var totals = quote.getTotals(),
30+
couponCode = this.couponCode,
31+
isApplied = this.isApplied,
32+
couponCodeValue;
33+
34+
if (totals()) {
35+
couponCode(totals()['coupon_code']);
36+
}
37+
38+
couponCodeValue = couponCode();
39+
isApplied(typeof couponCodeValue === 'string' && couponCodeValue.length > 0);
40+
41+
this._super();
42+
},
3843

3944
/**
4045
* Coupon code application procedure
4146
*/
4247
apply: function () {
4348
if (this.validate()) {
44-
setCouponCodeAction(couponCode(), isApplied);
49+
setCouponCodeAction(this.couponCode(), this.isApplied);
4550
}
4651
},
4752

@@ -50,8 +55,8 @@ define([
5055
*/
5156
cancel: function () {
5257
if (this.validate()) {
53-
couponCode('');
54-
cancelCouponAction(isApplied);
58+
this.couponCode('');
59+
cancelCouponAction(this.isApplied);
5560
}
5661
},
5762

@@ -71,4 +76,4 @@ define([
7176
return $(form).validation() && $(form).validation('isValid');
7277
}
7378
});
74-
});
79+
});

0 commit comments

Comments
 (0)