@@ -9,8 +9,10 @@ define([
9
9
'Magento_Checkout/js/model/cart/totals-processor/default' ,
10
10
'Magento_Checkout/js/model/shipping-service' ,
11
11
'Magento_Checkout/js/model/cart/cache' ,
12
- 'Magento_Customer/js/customer-data'
13
- ] , function ( quote , defaultProcessor , totalsDefaultProvider , shippingService , cartCache , customerData ) {
12
+ 'Magento_Customer/js/customer-data' ,
13
+ 'Magento_Checkout/js/checkout-data' ,
14
+ 'Magento_Checkout/js/action/select-shipping-method'
15
+ ] , function ( quote , defaultProcessor , totalsDefaultProvider , shippingService , cartCache , customerData , checkoutData , selectShippingMethodAction ) {
14
16
'use strict' ;
15
17
16
18
var rateProcessors = { } ,
@@ -35,8 +37,9 @@ define([
35
37
// check if user data not changed -> load rates from cache
36
38
if ( ! cartCache . isChanged ( 'address' , quote . shippingAddress ( ) ) &&
37
39
! cartCache . isChanged ( 'cartVersion' , customerData . get ( 'cart' ) ( ) [ 'data_id' ] ) &&
38
- cartCache . get ( 'rates' ) && cartCache . get ( 'totals' )
40
+ cartCache . get ( 'rates' ) // && cartCache.get('totals')
39
41
) {
42
+
40
43
shippingService . setShippingRates ( cartCache . get ( 'rates' ) ) ;
41
44
quote . setTotals ( cartCache . get ( 'totals' ) ) ;
42
45
return ;
@@ -53,8 +56,12 @@ define([
53
56
cartCache . set ( 'rates' , rates ) ;
54
57
} ) ;
55
58
56
- // update totals based on shipping address / rates changes
57
- totalsDefaultProvider . estimateTotals ( quote . shippingAddress ( ) ) ;
59
+ // update totals based on updated shipping address / rates changes
60
+ if ( cartCache . get ( 'address' ) &&
61
+ ( ! quote . shippingMethod ( ) || ! quote . shippingMethod ( ) [ 'method_code' ] )
62
+ ) {
63
+ totalsDefaultProvider . estimateTotals ( quote . shippingAddress ( ) ) ;
64
+ }
58
65
}
59
66
} ,
60
67
@@ -80,7 +87,9 @@ define([
80
87
}
81
88
} ;
82
89
83
-
90
+ /*if (!quote.shippingMethod() && cartCache.get('rates')) {
91
+ selectShippingMethodAction(cartCache.get('rates')[0]);
92
+ }*/
84
93
quote . shippingAddress . subscribe ( estimateTotalsAndUpdateRates ) ;
85
94
quote . shippingMethod . subscribe ( estimateTotalsShipping ) ;
86
95
quote . billingAddress . subscribe ( estimateTotalsBilling ) ;
0 commit comments