File tree Expand file tree Collapse file tree 6 files changed +177
-0
lines changed
app/code/Magento/LoginAsCustomer Expand file tree Collapse file tree 6 files changed +177
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \LoginAsCustomer \CustomerData ;
9
+
10
+ use Magento \Customer \CustomerData \SectionSourceInterface ;
11
+ use Magento \Customer \Model \Session ;
12
+
13
+ /**
14
+ * Customer data for the logged_as_customer section
15
+ */
16
+ class LoginAsCustomer implements SectionSourceInterface
17
+ {
18
+ /**
19
+ * @var Session
20
+ */
21
+ private $ customerSession ;
22
+
23
+ /**
24
+ * LoginAsCustomer constructor.
25
+ * @param Session $customerSession
26
+ */
27
+ public function __construct (
28
+ Session $ customerSession
29
+ ) {
30
+ $ this ->customerSession = $ customerSession ;
31
+ }
32
+
33
+ /**
34
+ * Retrieve private customer data for the logged_as_customer section
35
+ * @return array
36
+ */
37
+ public function getSectionData ():array
38
+ {
39
+ if (!$ this ->customerSession ->getCustomerId ()) {
40
+ return [];
41
+ }
42
+
43
+ return [
44
+ 'admin_user_id ' => $ this ->customerSession ->getLoggedAsCustomerAdmindId (),
45
+ ];
46
+ }
47
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \LoginAsCustomer \ViewModel ;
9
+
10
+ /**
11
+ * View model to get extension configuration in the template
12
+ */
13
+ class Configuration implements \Magento \Framework \View \Element \Block \ArgumentInterface
14
+ {
15
+
16
+ /**
17
+ * @var \Magento\LoginAsCustomer\Model\Config
18
+ */
19
+ private $ config ;
20
+
21
+ /**
22
+ * Configuration constructor.
23
+ * @param \Magento\LoginAsCustomer\Model\Config $config
24
+ */
25
+ public function __construct (
26
+ \Magento \LoginAsCustomer \Model \Config $ config
27
+ ) {
28
+ $ this ->config = $ config ;
29
+ }
30
+
31
+ /**
32
+ * Retrieve true if login as a customer is enabled
33
+ * @return bool
34
+ */
35
+ public function isEnabled ():bool
36
+ {
37
+ return $ this ->config ->isEnabled ();
38
+ }
39
+ }
Original file line number Diff line number Diff line change 9
9
<type name =" Magento\PageCache\Model\Config" >
10
10
<plugin name =" las-cache-is-enabled" type =" Magento\LoginAsCustomer\Model\PageCache\ConfigPlugin" />
11
11
</type >
12
+
13
+ <type name =" Magento\Customer\CustomerData\SectionPoolInterface" >
14
+ <arguments >
15
+ <argument name =" sectionSourceMap" xsi : type =" array" >
16
+ <item name =" logged_as_customer" xsi : type =" string" >Magento\LoginAsCustomer\CustomerData\LoginAsCustomer</item >
17
+ </argument >
18
+ </arguments >
19
+ </type >
12
20
</config >
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" ?>
2
+ <!--
3
+ /**
4
+ * Copyright © Magento, Inc. All rights reserved.
5
+ * See COPYING.txt for license details.
6
+ */
7
+ -->
8
+ <page xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : noNamespaceSchemaLocation =" urn:magento:framework:View/Layout/etc/page_configuration.xsd" >
9
+ <body >
10
+ <referenceContainer name =" after.body.start" >
11
+ <block name =" login_as_customer_notices" template =" Magento_LoginAsCustomer::html/notices.phtml" >
12
+ <arguments >
13
+ <argument name =" config" xsi : type =" object" >Magento\LoginAsCustomer\ViewModel\Configuration</argument >
14
+ </arguments >
15
+ </block >
16
+ </referenceContainer >
17
+ </body >
18
+ </page >
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+
7
+ /** @var \Magento\Framework\View\Element\Template $block */
8
+ ?>
9
+ <?php if ($ block ->getConfig ()->isEnabled ()) : ?>
10
+ <div data-bind="scope: 'loginAsCustomer'" >
11
+ <div class="message global demo" data-bind="visible: isVisible" style="display: none">
12
+ <div class="content">
13
+ <p data-bind="text: new String('Attention! You are logged in as the customer.')"></p>
14
+ </div>
15
+ </div>
16
+ </div>
17
+ <script type="text/x-magento-init">
18
+ {
19
+ "*": {
20
+ "Magento_Ui/js/core/app": {
21
+ "components": {
22
+ "loginAsCustomer": {
23
+ "component": "Magento_LoginAsCustomer/js/view/loginAsCustomer"
24
+ }
25
+ }
26
+ }
27
+ }
28
+ }
29
+ </script>
30
+ <?php endif ; ?>
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright © Magento, Inc. All rights reserved.
3
+ * See COPYING.txt for license details.
4
+ */
5
+
6
+ define ( [
7
+ 'uiComponent' ,
8
+ 'Magento_Customer/js/customer-data'
9
+ ] , function ( Component , customerData ) {
10
+ 'use strict' ;
11
+
12
+ return Component . extend ( {
13
+
14
+ defaults : {
15
+ isVisible : false
16
+ } ,
17
+
18
+ /** @inheritdoc */
19
+ initialize : function ( ) {
20
+ this . _super ( ) ;
21
+
22
+ this . customer = customerData . get ( 'customer' ) ;
23
+ this . loginAsCustomer = customerData . get ( 'logged_as_customer' ) ;
24
+ this . isVisible ( this . loginAsCustomer ( ) . admin_user_id ) ;
25
+ } ,
26
+
27
+ /** @inheritdoc */
28
+ initObservable : function ( ) {
29
+ this . _super ( )
30
+ . observe ( 'isVisible' ) ;
31
+
32
+ return this ;
33
+ }
34
+ } ) ;
35
+ } ) ;
You can’t perform that action at this time.
0 commit comments