8
8
'uiComponent' ,
9
9
'Magento_Customer/js/customer-data' ,
10
10
'mage/translate'
11
- ] , function ( $ , Component , customerData ) {
11
+ ] , function ( $ , Component , customer ) {
12
12
'use strict' ;
13
13
14
14
return Component . extend ( {
@@ -19,23 +19,53 @@ define([
19
19
20
20
/** @inheritdoc */
21
21
initialize : function ( ) {
22
+ var customerData , loggedAsCustomerData ;
23
+
22
24
this . _super ( ) ;
23
25
24
- this . customer = customerData . get ( 'customer' ) ;
25
- this . loginAsCustomer = customerData . get ( 'loggedAsCustomer' ) ;
26
- this . isVisible ( this . loginAsCustomer ( ) . adminUserId ) ;
26
+ customerData = customer . get ( 'customer' ) ;
27
+ loggedAsCustomerData = customer . get ( 'loggedAsCustomer' ) ;
28
+
29
+ customerData . subscribe ( function ( data ) {
30
+ this . fullname = data . fullname ;
31
+ this . updateBanner ( ) ;
32
+ } . bind ( this ) ) ;
33
+ loggedAsCustomerData . subscribe ( function ( data ) {
34
+ this . adminUserId = data . adminUserId ;
35
+ this . websiteName = data . websiteName ;
36
+ this . updateBanner ( ) ;
37
+ } . bind ( this ) ) ;
38
+
39
+ this . fullname = customerData ( ) . fullname ;
40
+ this . adminUserId = loggedAsCustomerData ( ) . adminUserId ;
41
+ this . websiteName = loggedAsCustomerData ( ) . websiteName ;
27
42
28
- this . notificationText = $ . mage . __ ( 'You are connected as <strong>%1</strong> on %2' )
29
- . replace ( '%1' , this . customer ( ) . fullname )
30
- . replace ( '%2' , this . loginAsCustomer ( ) . websiteName ) ;
43
+ this . updateBanner ( ) ;
31
44
} ,
32
45
33
46
/** @inheritdoc */
34
47
initObservable : function ( ) {
35
48
this . _super ( )
36
- . observe ( 'isVisible' ) ;
49
+ . observe ( [ 'isVisible' , 'notificationText' ] ) ;
37
50
38
51
return this ;
52
+ } ,
53
+
54
+ /**
55
+ * Update banner area
56
+ *
57
+ * @returns void
58
+ */
59
+ updateBanner : function ( ) {
60
+ if ( this . adminUserId !== undefined ) {
61
+ this . isVisible ( this . adminUserId ) ;
62
+ }
63
+
64
+ if ( this . fullname !== undefined && this . websiteName !== undefined ) {
65
+ this . notificationText ( $ . mage . __ ( 'You are connected as <strong>%1</strong> on %2' )
66
+ . replace ( '%1' , this . fullname )
67
+ . replace ( '%2' , this . websiteName ) ) ;
68
+ }
39
69
}
40
70
} ) ;
41
71
} ) ;
0 commit comments