88 'uiComponent' ,
99 'Magento_Customer/js/customer-data' ,
1010 'mage/translate'
11- ] , function ( $ , Component , customerData ) {
11+ ] , function ( $ , Component , customer ) {
1212 'use strict' ;
1313
1414 return Component . extend ( {
@@ -19,23 +19,53 @@ define([
1919
2020 /** @inheritdoc */
2121 initialize : function ( ) {
22+ var customerData , loggedAsCustomerData ;
23+
2224 this . _super ( ) ;
2325
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 ;
2742
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 ( ) ;
3144 } ,
3245
3346 /** @inheritdoc */
3447 initObservable : function ( ) {
3548 this . _super ( )
36- . observe ( 'isVisible' ) ;
49+ . observe ( [ 'isVisible' , 'notificationText' ] ) ;
3750
3851 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+ }
3969 }
4070 } ) ;
4171} ) ;
0 commit comments