4
4
*/
5
5
6
6
define ( [
7
+ 'jquery' ,
7
8
'Magento_Checkout/js/model/quote'
8
- ] , function ( quote ) {
9
+ ] , function ( $ , quote ) {
9
10
'use strict' ;
10
11
11
12
var storePickupShippingInformation = {
@@ -14,7 +15,26 @@ define([
14
15
shippingMethodTitle : '' ,
15
16
} ,
16
17
17
- initObservable : function ( ) {
18
+ initialize : function ( ) {
19
+ this . _super ( ) ;
20
+
21
+ $ ( document ) . ajaxComplete ( ( e , xhr , settings ) => {
22
+ if ( settings . url . includes ( 'shipping-information' ) ) {
23
+ if ( xhr . status === 200 ) {
24
+ let response = JSON . parse ( xhr . responseText ) ;
25
+
26
+ window . checkoutConfig . totalsData . extension_attributes [ 0 ] = {
27
+ 'carrier_title' : response . totals . extension_attributes . shipping_methods [ 0 ] . carrier_title ,
28
+ 'method_title' : response . totals . extension_attributes . shipping_methods [ 0 ] . method_title
29
+ }
30
+
31
+ this . setShippingMethodTitle ( ) ;
32
+ }
33
+ }
34
+ } ) ;
35
+ } ,
36
+
37
+ initObservable ( ) {
18
38
this . _super ( ) . observe ( [ 'shippingMethodTitle' ] ) ;
19
39
return this ;
20
40
} ,
@@ -24,58 +44,47 @@ define([
24
44
*
25
45
* @return {String }
26
46
*/
27
- getShippingMethodTitle : function ( ) {
47
+ getShippingMethodTitle ( ) {
28
48
this . shippingMethodTitle ( '' ) ;
29
49
30
- quote . totals . subscribe ( ( ) => {
31
- var shippingMethod = quote . shippingMethod ( ) ,
32
- shippingMethodTitle = '' ,
33
- locationName = '' ,
34
- title ;
35
-
36
- if ( window . checkoutConfig . totalsData . extension_attributes [ 0 ] ) {
37
- const carrier_title = shippingMethod [ 'carrier_title' ] ? `${ shippingMethod [ 'carrier_title' ] } ` : '' ;
38
- const method_title = shippingMethod [ 'method_title' ] ? shippingMethod [ 'method_title' ] : '' ;
39
-
40
- if ( typeof shippingMethod [ 'method_title' ] !== 'undefined' ) {
41
- shippingMethodTitle = carrier_title + ' - ' + method_title ;
42
- }
43
-
44
- shippingMethod = window . checkoutConfig . totalsData . extension_attributes [ 0 ] ;
45
- this . shippingMethodTitle ( shippingMethodTitle ) ;
46
- } else {
47
- shippingMethod = quote . shippingMethod ( ) ;
50
+ // Trigger setting shipping method title if quote total subscribe doesn't trigger
51
+ this . setShippingMethodTitle ( ) ;
48
52
49
- if ( ! this . isStorePickup ( ) ) {
50
- if ( ! shippingMethod ) return '' ;
53
+ quote . totals . subscribe ( ( ) => {
54
+ this . setShippingMethodTitle ( ) ;
55
+ } ) ;
56
+ } ,
51
57
52
- shippingMethodTitle = shippingMethod [ 'carrier_title' ] ;
58
+ setShippingMethodTitle ( ) {
59
+ if ( window . checkoutConfig . totalsData . extension_attributes [ 0 ] && window . checkoutConfig . paazlshipping ) {
60
+ const shippingMethod = window . checkoutConfig . totalsData . extension_attributes [ 0 ] ;
61
+ const carrier_title = shippingMethod [ 'carrier_title' ] ;
62
+ const method_title = shippingMethod [ 'method_title' ] ;
53
63
54
- if ( typeof shippingMethod [ 'method_title' ] !== 'undefined' ) {
55
- shippingMethodTitle += ' - ' + shippingMethod [ 'method_title' ] ;
56
- }
57
-
58
- return shippingMethodTitle ;
59
- }
60
-
61
- title = shippingMethod [ 'carrier_title' ] + ' - ' + shippingMethod [ 'method_title' ] ;
64
+ if ( carrier_title && method_title ) {
65
+ this . shippingMethodTitle ( carrier_title + ' - ' + method_title ) ;
66
+ }
67
+ } else {
68
+ this . getDefaultShippingMethodTitle ( ) ;
69
+ }
70
+ } ,
62
71
63
- if ( quote . shippingAddress ( ) . firstname !== undefined ) {
64
- locationName = quote . shippingAddress ( ) . firstname + ' ' + quote . shippingAddress ( ) . lastname ;
65
- title += ' "' + locationName + '" ';
66
- }
72
+ getDefaultShippingMethodTitle ( ) {
73
+ const shippingMethod = quote . shippingMethod ( ) ;
74
+ const carrier_title = shippingMethod ? shippingMethod [ 'carrier_title' ] : ' ';
75
+ const method_title = shippingMethod ? shippingMethod [ 'method_title' ] : '' ;
67
76
68
- return title ;
69
- }
70
- } ) ;
77
+ if ( carrier_title && method_title ) {
78
+ this . shippingMethodTitle ( carrier_title + ' - ' + method_title ) ;
79
+ }
71
80
} ,
72
81
73
82
/**
74
83
* Get is store pickup delivery method selected.
75
84
*
76
85
* @returns {Boolean }
77
86
*/
78
- isStorePickup : function ( ) {
87
+ isStorePickup ( ) {
79
88
var shippingMethod = quote . shippingMethod ( ) ,
80
89
isStorePickup = false ;
81
90
0 commit comments