@@ -12,8 +12,22 @@ define([
12
12
'Magento_Checkout/js/model/shipping-save-processor/payload-extender' ,
13
13
'Magento_Checkout/js/model/resource-url-manager' ,
14
14
'Magento_Checkout/js/model/error-processor' ,
15
- 'Paazl_CheckoutWidget/js/checkout/view/widget-config'
16
- ] , function ( $ , _ , ko , storage , quote , payloadExtender , resourceUrlManager , errorProcessor , widgetConfig ) {
15
+ 'Paazl_CheckoutWidget/js/checkout/view/widget-config' ,
16
+ 'Magento_Customer/js/model/customer' ,
17
+ 'Paazl_CheckoutWidget/js/checkout/model/shipping-locations' ,
18
+ ] , function (
19
+ $ ,
20
+ _ ,
21
+ ko ,
22
+ storage ,
23
+ quote ,
24
+ payloadExtender ,
25
+ resourceUrlManager ,
26
+ errorProcessor ,
27
+ widgetConfig ,
28
+ customer ,
29
+ shippingLocations
30
+ ) {
17
31
"use strict" ;
18
32
19
33
/**
@@ -78,25 +92,53 @@ define([
78
92
79
93
setShippingInformation : function ( ) {
80
94
const savedSelectedShippingAddress = quote . shippingAddress ( ) ;
81
- let ajaxHandled = false ;
82
95
83
96
widgetConfig . prototype . lock ( ) ;
84
97
this . _super ( ) ;
85
98
86
99
if ( savedSelectedShippingAddress . customerAddressId !== quote . shippingAddress ( ) . customerAddressId ) {
87
- quote . shippingAddress ( savedSelectedShippingAddress ) ;
88
-
89
- $ ( document ) . ajaxComplete ( ( _ , xhr , settings ) => {
90
- if ( ! ajaxHandled && settings . url . includes ( resourceUrlManager . getUrlForSetShippingInformation ( quote ) ) ) {
91
- ajaxHandled = true ;
92
- this . saveShippingInformation ( ) ;
93
- }
94
- } ) ;
100
+ this . updateShippingInfo ( savedSelectedShippingAddress ) ;
101
+ }
102
+
103
+ if ( ! shippingLocations . selectedLocationCode ( ) ) {
104
+ const customerAddressId = quote . shippingAddress ( ) . customerAddressId ;
105
+ const customerAddressList = customer . customerData . addresses ;
106
+
107
+ if ( customerAddressList ) {
108
+ const currentAddress = customerAddressList [ customerAddressId ] ;
109
+ const shippingAddress = Object . assign ( { } , quote . shippingAddress ( ) , {
110
+ firstname : currentAddress . firstname ,
111
+ lastname : currentAddress . lastname ,
112
+ countryId : currentAddress . country_id ,
113
+ region : typeof currentAddress . region === 'object' && currentAddress . region !== null
114
+ ? currentAddress . region . region
115
+ : currentAddress . region ,
116
+ city : currentAddress . city ,
117
+ postcode : currentAddress . postcode ,
118
+ street : Object . values ( currentAddress . street ) ,
119
+ telephone : currentAddress . telephone
120
+ } ) ;
121
+
122
+ this . updateShippingInfo ( shippingAddress ) ;
123
+ }
95
124
}
96
125
97
126
widgetConfig . prototype . unlock ( ) ;
98
127
} ,
99
128
129
+ updateShippingInfo ( address ) {
130
+ let ajaxHandled = false ;
131
+
132
+ quote . shippingAddress ( address ) ;
133
+
134
+ $ ( document ) . ajaxComplete ( ( _ , xhr , settings ) => {
135
+ if ( ! ajaxHandled && settings . url . includes ( resourceUrlManager . getUrlForSetShippingInformation ( quote ) ) ) {
136
+ ajaxHandled = true ;
137
+ this . saveShippingInformation ( ) ;
138
+ }
139
+ } ) ;
140
+ } ,
141
+
100
142
saveShippingInformation : function ( ) {
101
143
var payload ;
102
144
0 commit comments