Skip to content

Commit f51d740

Browse files
committed
MAGETWO-66627: [GitHub] Default Post Code is applied for all Order's addresses if zip is not required
1 parent d03bc98 commit f51d740

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([], function () {
6+
/**
7+
* Define necessity of using default post code value
8+
*/
9+
var useDefaultPostCode;
10+
11+
return {
12+
13+
/**
14+
* Resolve default post code
15+
*
16+
* @returns {string|undefined}
17+
*/
18+
resolve: function () {
19+
return useDefaultPostCode ? window.checkoutConfig.defaultPostcode : undefined;
20+
},
21+
22+
/**
23+
* Set state to useDefaultPostCode variable
24+
*
25+
* @param shouldUseDefaultPostCode
26+
* @returns {underscore}
27+
*/
28+
setUseDefaultPostCode: function (shouldUseDefaultPostCode)
29+
{
30+
useDefaultPostCode = shouldUseDefaultPostCode;
31+
return this;
32+
}
33+
};
34+
});

app/code/Magento/Ui/view/base/web/js/form/element/region.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
define([
1010
'underscore',
1111
'uiRegistry',
12-
'./select'
13-
], function (_, registry, Select) {
12+
'./select',
13+
'Magento_Checkout/js/model/default-post-code-resolver'
14+
], function (_, registry, Select, DefaultPostCodeResolver) {
1415
'use strict';
1516

1617
return Select.extend({
@@ -33,9 +34,10 @@ define([
3334
if (!value) {
3435
return;
3536
}
36-
3737
option = options[value];
38-
38+
DefaultPostCodeResolver
39+
.setUseDefaultPostCode('undefined' !== typeof option.is_zipcode_optional &&
40+
true === option.is_zipcode_optional ? false : true);
3941
if (this.skipValidation) {
4042
this.validation['required-entry'] = false;
4143
this.required(false);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'underscore',
7+
'Magento_Checkout/js/model/default-post-code-resolver'
8+
], function (_, DefaultPostCodeResolver) {
9+
'use strict';
10+
11+
describe('checkout/js/model/default-post-code-resolver', function () {
12+
var defaultPostCodeResolver;
13+
14+
beforeEach(function () {
15+
defaultPostCodeResolver = DefaultPostCodeResolver;
16+
});
17+
18+
it('resolve', function () {
19+
expect(defaultPostCodeResolver.resolve()).toBe(undefined);
20+
});
21+
});
22+
});

0 commit comments

Comments
 (0)