@@ -18,7 +18,8 @@ define([
18
18
'Magento_Checkout/js/action/select-payment-method' ,
19
19
'Magento_Checkout/js/model/address-converter' ,
20
20
'Magento_Checkout/js/action/select-billing-address' ,
21
- 'Magento_Checkout/js/action/create-billing-address'
21
+ 'Magento_Checkout/js/action/create-billing-address' ,
22
+ 'underscore'
22
23
] , function (
23
24
addressList ,
24
25
quote ,
@@ -30,7 +31,8 @@ define([
30
31
selectPaymentMethodAction ,
31
32
addressConverter ,
32
33
selectBillingAddress ,
33
- createBillingAddress
34
+ createBillingAddress ,
35
+ _
34
36
) {
35
37
'use strict' ;
36
38
@@ -39,9 +41,10 @@ define([
39
41
if ( checkoutData . getShippingAddressFromData ( ) ) {
40
42
var address = addressConverter . formAddressDataToQuoteAddress ( checkoutData . getShippingAddressFromData ( ) ) ;
41
43
selectShippingAddress ( address ) ;
44
+ } else {
45
+ this . resolveShippingAddress ( ) ;
42
46
}
43
- this . resolveShippingAddress ( true ) ;
44
- if ( quote . isVirtual ) {
47
+ if ( quote . isVirtual ( ) ) {
45
48
if ( checkoutData . getBillingAddressFromData ( ) ) {
46
49
address = addressConverter . formAddressDataToQuoteAddress ( checkoutData . getBillingAddressFromData ( ) ) ;
47
50
selectBillingAddress ( address ) ;
@@ -61,7 +64,6 @@ define([
61
64
} ,
62
65
63
66
applyShippingAddress : function ( isEstimatedAddress ) {
64
-
65
67
if ( addressList ( ) . length == 0 ) {
66
68
var address = addressConverter . formAddressDataToQuoteAddress ( checkoutData . getShippingAddressFromData ( ) ) ;
67
69
selectShippingAddress ( address ) ;
@@ -104,40 +106,37 @@ define([
104
106
105
107
resolveShippingRates : function ( ratesData ) {
106
108
var selectedShippingRate = checkoutData . getSelectedShippingRate ( ) ;
107
- var rateIsAvailable = false ;
109
+ var availableRate = false ;
108
110
109
111
if ( ratesData . length == 1 ) {
110
112
//set shipping rate if we have only one available shipping rate
111
113
selectShippingMethodAction ( ratesData [ 0 ] ) ;
112
114
return ;
113
115
}
114
116
115
- if ( quote . shippingMethod ( ) ) {
116
- rateIsAvailable = ratesData . some ( function ( rate ) {
117
+ if ( quote . shippingMethod ( ) ) {
118
+ availableRate = _ . find ( ratesData , function ( rate ) {
117
119
return rate . carrier_code == quote . shippingMethod ( ) . carrier_code
118
120
&& rate . method_code == quote . shippingMethod ( ) . method_code ;
119
121
} ) ;
120
122
}
121
123
122
- if ( ! rateIsAvailable && selectedShippingRate ) {
123
- rateIsAvailable = ratesData . some ( function ( rate ) {
124
- if ( rate . carrier_code + "_" + rate . method_code == selectedShippingRate ) {
125
- selectShippingMethodAction ( rate ) ;
126
- return true ;
127
- }
128
- return false ;
129
-
124
+ if ( ! availableRate && selectedShippingRate ) {
125
+ availableRate = _ . find ( ratesData , function ( rate ) {
126
+ return rate . carrier_code + "_" + rate . method_code === selectedShippingRate ;
130
127
} ) ;
131
128
}
132
129
133
- if ( ! rateIsAvailable && window . checkoutConfig . selectedShippingMethod ) {
134
- rateIsAvailable = true ;
130
+ if ( ! availableRate && window . checkoutConfig . selectedShippingMethod ) {
131
+ availableRate = true ;
135
132
selectShippingMethodAction ( window . checkoutConfig . selectedShippingMethod ) ;
136
133
}
137
134
138
135
//Unset selected shipping method if not available
139
- if ( ! rateIsAvailable ) {
136
+ if ( ! availableRate ) {
140
137
selectShippingMethodAction ( null ) ;
138
+ } else {
139
+ selectShippingMethodAction ( availableRate ) ;
141
140
}
142
141
} ,
143
142
0 commit comments