Skip to content

Commit 56b745f

Browse files
ENGCOM-5455: Fixes issue 22112 (#22112) … #23656
- Merge Pull Request #23656 from rsimmons07/magento2:feature/Remove_Shipping_Rates_Validation_From_Billing_Address_Form - Merged commits: 1. 571a72c 2. 2756bc9 3. e6ab6a5 4. 1c9df24 5. a3c3061
2 parents ce69707 + a3c3061 commit 56b745f

File tree

2 files changed

+85
-3
lines changed

2 files changed

+85
-3
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'jquery',
8+
'Magento_Checkout/js/model/postcode-validator',
9+
'mage/translate',
10+
'uiRegistry'
11+
], function (
12+
$,
13+
postcodeValidator,
14+
$t,
15+
uiRegistry
16+
) {
17+
'use strict';
18+
19+
var postcodeElementName = 'postcode';
20+
21+
return {
22+
validateZipCodeTimeout: 0,
23+
validateDelay: 2000,
24+
25+
/**
26+
* Perform postponed binding for fieldset elements
27+
*
28+
* @param {String} formPath
29+
*/
30+
initFields: function (formPath) {
31+
var self = this;
32+
33+
uiRegistry.async(formPath + '.' + postcodeElementName)(self.bindHandler.bind(self));
34+
},
35+
36+
/**
37+
* @param {Object} element
38+
* @param {Number} delay
39+
*/
40+
bindHandler: function (element, delay) {
41+
var self = this;
42+
43+
delay = typeof delay === 'undefined' ? self.validateDelay : delay;
44+
45+
element.on('value', function () {
46+
clearTimeout(self.validateZipCodeTimeout);
47+
self.validateZipCodeTimeout = setTimeout(function () {
48+
self.postcodeValidation(element);
49+
}, delay);
50+
});
51+
},
52+
53+
/**
54+
* @param {Object} postcodeElement
55+
* @return {*}
56+
*/
57+
postcodeValidation: function (postcodeElement) {
58+
var countryId = $('select[name="country_id"]:visible').val(),
59+
validationResult,
60+
warnMessage;
61+
62+
if (postcodeElement == null || postcodeElement.value() == null) {
63+
return true;
64+
}
65+
66+
postcodeElement.warn(null);
67+
validationResult = postcodeValidator.validate(postcodeElement.value(), countryId);
68+
69+
if (!validationResult) {
70+
warnMessage = $t('Provided Zip/Postal Code seems to be invalid.');
71+
72+
if (postcodeValidator.validatedPostCodeExample.length) {
73+
warnMessage += $t(' Example: ') + postcodeValidator.validatedPostCodeExample.join('; ') + '. ';
74+
}
75+
warnMessage += $t('If you believe it is the right one you can ignore this notice.');
76+
postcodeElement.warn(warnMessage);
77+
}
78+
79+
return validationResult;
80+
}
81+
};
82+
});

app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ define([
1818
'Magento_Checkout/js/action/set-billing-address',
1919
'Magento_Ui/js/model/messageList',
2020
'mage/translate',
21-
'Magento_Checkout/js/model/shipping-rates-validator'
21+
'Magento_Checkout/js/model/billing-address-postcode-validator'
2222
],
2323
function (
2424
ko,
@@ -35,7 +35,7 @@ function (
3535
setBillingAddressAction,
3636
globalMessageList,
3737
$t,
38-
shippingRatesValidator
38+
billingAddressPostcodeValidator
3939
) {
4040
'use strict';
4141

@@ -66,7 +66,7 @@ function (
6666
quote.paymentMethod.subscribe(function () {
6767
checkoutDataResolver.resolveBillingAddress();
6868
}, this);
69-
shippingRatesValidator.initFields(this.get('name') + '.form-fields');
69+
billingAddressPostcodeValidator.initFields(this.get('name') + '.form-fields');
7070
},
7171

7272
/**

0 commit comments

Comments
 (0)