@@ -58,18 +58,22 @@ define(
58
58
return ! quote . isVirtual ( ) ;
59
59
} ,
60
60
selectShippingAddress : function ( ) {
61
- var additionalData = { } ;
62
- var billingAddress = quote . getBillingAddress ( ) ( ) ;
61
+ var additionalFields ,
62
+ addressData ,
63
+ additionalData = { } ,
64
+ billingAddress = quote . getBillingAddress ( ) ( ) ;
65
+
63
66
if ( ! billingAddress . customerAddressId || ! this . visible ( ) ) {
64
67
/**
65
68
* All the the input fields that are not a part of the address but need to be submitted
66
69
* in the same request must have data-scope attribute set
67
70
*/
68
- var additionalFields = $ ( 'input[data-scope="additionalAddressData"]' ) . serializeArray ( ) ;
71
+ additionalFields = $ ( 'input[data-scope="additionalAddressData"]' ) . serializeArray ( ) ;
69
72
additionalFields . forEach ( function ( field ) {
70
73
additionalData [ field . name ] = field . value ;
71
74
} ) ;
72
75
}
76
+
73
77
if ( ! newAddressSelected ( ) ) {
74
78
selectShippingAddress (
75
79
addressList . getAddressById ( this . selectedAddressId ( ) ) ,
@@ -80,23 +84,32 @@ define(
80
84
if ( this . visible ( ) ) {
81
85
this . validate ( ) ;
82
86
}
87
+
83
88
if ( ! this . source . get ( 'params.invalid' ) ) {
84
- var addressData = this . source . get ( 'shippingAddress' ) ;
89
+ addressData = this . source . get ( 'shippingAddress' ) ;
85
90
selectShippingAddress ( addressData , this . sameAsBilling ( ) , additionalData ) ;
86
91
}
87
92
}
88
93
} ,
89
94
sameAsBillingClick : function ( ) {
95
+ var billingAddress ,
96
+ shippingAddress ,
97
+ property ;
98
+
90
99
addressList . isBillingSameAsShipping = ! addressList . isBillingSameAsShipping ;
100
+
91
101
if ( this . sameAsBilling ( ) ) {
92
- var billingAddress = quote . getBillingAddress ( ) ( ) ;
102
+ billingAddress = quote . getBillingAddress ( ) ( ) ;
103
+
93
104
if ( billingAddress . customerAddressId ) {
94
105
this . selectedAddressId ( billingAddress . customerAddressId ) ;
95
106
newAddressSelected ( false ) ;
107
+
96
108
} else {
97
109
// copy billing address data to shipping address form if customer uses new address for billing
98
- var shippingAddress = this . source . get ( 'shippingAddress' ) ;
99
- for ( var property in billingAddress ) {
110
+ shippingAddress = this . source . get ( 'shippingAddress' ) ;
111
+
112
+ for ( property in billingAddress ) {
100
113
if ( billingAddress . hasOwnProperty ( property ) && shippingAddress . hasOwnProperty ( property ) ) {
101
114
if ( typeof billingAddress [ property ] === 'string' ) {
102
115
this . source . set ( 'shippingAddress.' + property , billingAddress [ property ] ) ;
@@ -105,6 +118,7 @@ define(
105
118
}
106
119
}
107
120
}
121
+
108
122
this . selectedAddressId ( null ) ;
109
123
newAddressSelected ( true ) ;
110
124
}
@@ -113,9 +127,11 @@ define(
113
127
} ,
114
128
onAddressChange : function ( ) {
115
129
var billingAddress = quote . getBillingAddress ( ) ;
130
+
116
131
if ( this . selectedAddressId ( ) !== billingAddress ( ) . customerAddressId ) {
117
132
this . sameAsBilling ( false ) ;
118
133
}
134
+
119
135
if ( this . selectedAddressId ( ) === null ) {
120
136
newAddressSelected ( true ) ;
121
137
} else {
0 commit comments