Skip to content

Commit 07f03fe

Browse files
magento/magento2-login-as-customer#144: Banner is not shown on Category page if Disable Page Cache For Admin User = No.
1 parent d9c02ed commit 07f03fe

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\LoginAsCustomerFrontendUi\Plugin;
8+
9+
use Magento\Framework\Session\SessionManagerInterface;
10+
use Magento\LoginAsCustomerApi\Api\ConfigInterface;
11+
use Magento\LoginAsCustomerApi\Api\GetLoggedAsCustomerAdminIdInterface;
12+
use Magento\LoginAsCustomerApi\Api\SetLoggedAsCustomerAdminIdInterface;
13+
14+
/**
15+
* Keep adminId in customer session if session data is cleared.
16+
*/
17+
class KeepLoginAsCustomerSessionDataPlugin
18+
{
19+
/**
20+
* @var ConfigInterface
21+
*/
22+
private $config;
23+
24+
/**
25+
* @var GetLoggedAsCustomerAdminIdInterface
26+
*/
27+
private $getLoggedAsCustomerAdminId;
28+
29+
/**
30+
* @var SetLoggedAsCustomerAdminIdInterface
31+
*/
32+
private $setLoggedAsCustomerAdminId;
33+
34+
/**
35+
* @param ConfigInterface $config
36+
* @param GetLoggedAsCustomerAdminIdInterface $getLoggedAsCustomerAdminId
37+
* @param SetLoggedAsCustomerAdminIdInterface $setLoggedAsCustomerAdminId
38+
*/
39+
public function __construct(
40+
ConfigInterface $config,
41+
GetLoggedAsCustomerAdminIdInterface $getLoggedAsCustomerAdminId,
42+
SetLoggedAsCustomerAdminIdInterface $setLoggedAsCustomerAdminId
43+
) {
44+
$this->config = $config;
45+
$this->getLoggedAsCustomerAdminId = $getLoggedAsCustomerAdminId;
46+
$this->setLoggedAsCustomerAdminId = $setLoggedAsCustomerAdminId;
47+
}
48+
49+
/**
50+
* Keep adminId in customer session if session data is cleared.
51+
*
52+
* @param SessionManagerInterface $subject
53+
* @param \Closure $proceed
54+
* @return SessionManagerInterface
55+
*
56+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
57+
*/
58+
public function aroundClearStorage(
59+
SessionManagerInterface $subject,
60+
\Closure $proceed
61+
): SessionManagerInterface {
62+
$enabled = $this->config->isEnabled();
63+
$adminId = $enabled ? $this->getLoggedAsCustomerAdminId->execute() : null;
64+
$result = $proceed();
65+
if ($enabled && $adminId) {
66+
$this->setLoggedAsCustomerAdminId->execute($adminId);
67+
}
68+
69+
return $result;
70+
}
71+
}

app/code/Magento/LoginAsCustomerFrontendUi/etc/frontend/di.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@
1717
<plugin name="invalidate_expired_session_plugin"
1818
type="Magento\LoginAsCustomerFrontendUi\Plugin\InvalidateExpiredSessionPlugin"/>
1919
</type>
20+
<type name="Magento\Framework\Session\SessionManagerInterface">
21+
<plugin name="keep_login_as_customer_session_data"
22+
type="Magento\LoginAsCustomerFrontendUi\Plugin\KeepLoginAsCustomerSessionDataPlugin"/>
23+
</type>
2024
</config>

0 commit comments

Comments
 (0)