Skip to content

Commit 8ceaa21

Browse files
committed
Merge remote-tracking branch 'origin/module-login-as-customer' into module-login-as-customer
2 parents eb3ea37 + 51b1ffe commit 8ceaa21

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

app/code/Magento/LoginAsCustomerFrontendUi/view/frontend/layout/loginascustomer_login_index.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</action>
1414
</referenceBlock>
1515
<referenceContainer name="content">
16-
<block class="Magento\Framework\View\Element\Template" name="loginascustomer_login" template="Magento_LoginAsCustomerFrontendUi::login.phtml"/>
16+
<block class="Magento\Framework\View\Element\Template" name="loginascustomer_login" template="Magento_LoginAsCustomerFrontendUi::login.phtml" cacheable="false"/>
1717
</referenceContainer>
1818
</body>
1919
</page>

app/code/Magento/LoginAsCustomerFrontendUi/view/frontend/web/js/view/loginAsCustomer.js

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ define([
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

Comments
 (0)