From 625e57eae13c6dd47e758c9fdd56bfbfd54fcb4a Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Tue, 23 Jun 2020 16:23:18 +0300 Subject: [PATCH 01/10] magento/magento2-login-as-customer#144: Session interfaces introduction. --- .../Model/AuthenticateCustomerBySecret.php | 13 +++++- .../Model/GetLoggedAsCustomerAdminId.php | 40 +++++++++++++++++++ .../Model/GetLoggedAsCustomerCustomerId.php | 40 +++++++++++++++++++ .../Model/SetLoggedAsCustomerAdminId.php | 40 +++++++++++++++++++ .../Model/SetLoggedAsCustomerCustomerId.php | 40 +++++++++++++++++++ .../Plugin/AdminLogoutPlugin.php | 22 +++++----- app/code/Magento/LoginAsCustomer/etc/di.xml | 4 ++ .../Controller/Adminhtml/Login/Login.php | 15 ++++++- .../GetLoggedAsCustomerAdminIdInterface.php | 23 +++++++++++ ...GetLoggedAsCustomerCustomerIdInterface.php | 23 +++++++++++ .../SetLoggedAsCustomerAdminIdInterface.php | 24 +++++++++++ ...SetLoggedAsCustomerCustomerIdInterface.php | 24 +++++++++++ .../CustomerData/LoginAsCustomerUi.php | 17 ++++++-- .../Plugin/InvalidateExpiredSessionPlugin.php | 13 +++++- .../Config/DisablePageCacheIfNeededPlugin.php | 14 +++---- .../FrontAddCommentOnOrderPlacementPlugin.php | 20 +++++----- 16 files changed, 335 insertions(+), 37 deletions(-) create mode 100644 app/code/Magento/LoginAsCustomer/Model/GetLoggedAsCustomerAdminId.php create mode 100644 app/code/Magento/LoginAsCustomer/Model/GetLoggedAsCustomerCustomerId.php create mode 100644 app/code/Magento/LoginAsCustomer/Model/SetLoggedAsCustomerAdminId.php create mode 100644 app/code/Magento/LoginAsCustomer/Model/SetLoggedAsCustomerCustomerId.php create mode 100644 app/code/Magento/LoginAsCustomerApi/Api/GetLoggedAsCustomerAdminIdInterface.php create mode 100644 app/code/Magento/LoginAsCustomerApi/Api/GetLoggedAsCustomerCustomerIdInterface.php create mode 100644 app/code/Magento/LoginAsCustomerApi/Api/SetLoggedAsCustomerAdminIdInterface.php create mode 100644 app/code/Magento/LoginAsCustomerApi/Api/SetLoggedAsCustomerCustomerIdInterface.php diff --git a/app/code/Magento/LoginAsCustomer/Model/AuthenticateCustomerBySecret.php b/app/code/Magento/LoginAsCustomer/Model/AuthenticateCustomerBySecret.php index a728f4c3a4393..a27c1c43ad965 100644 --- a/app/code/Magento/LoginAsCustomer/Model/AuthenticateCustomerBySecret.php +++ b/app/code/Magento/LoginAsCustomer/Model/AuthenticateCustomerBySecret.php @@ -11,6 +11,7 @@ use Magento\Framework\Exception\LocalizedException; use Magento\LoginAsCustomerApi\Api\AuthenticateCustomerBySecretInterface; use Magento\LoginAsCustomerApi\Api\GetAuthenticationDataBySecretInterface; +use Magento\LoginAsCustomerApi\Api\SetLoggedAsCustomerAdminIdInterface; /** * @inheritdoc @@ -29,16 +30,24 @@ class AuthenticateCustomerBySecret implements AuthenticateCustomerBySecretInterf */ private $customerSession; + /** + * @var SetLoggedAsCustomerAdminIdInterface + */ + private $setLoggedAsCustomerAdminId; + /** * @param GetAuthenticationDataBySecretInterface $getAuthenticationDataBySecret * @param Session $customerSession + * @param SetLoggedAsCustomerAdminIdInterface $setLoggedAsCustomerAdminId */ public function __construct( GetAuthenticationDataBySecretInterface $getAuthenticationDataBySecret, - Session $customerSession + Session $customerSession, + SetLoggedAsCustomerAdminIdInterface $setLoggedAsCustomerAdminId ) { $this->getAuthenticationDataBySecret = $getAuthenticationDataBySecret; $this->customerSession = $customerSession; + $this->setLoggedAsCustomerAdminId = $setLoggedAsCustomerAdminId; } /** @@ -58,6 +67,6 @@ public function execute(string $secret): void } $this->customerSession->regenerateId(); - $this->customerSession->setLoggedAsCustomerAdmindId($authenticationData->getAdminId()); + $this->setLoggedAsCustomerAdminId->execute($authenticationData->getAdminId()); } } diff --git a/app/code/Magento/LoginAsCustomer/Model/GetLoggedAsCustomerAdminId.php b/app/code/Magento/LoginAsCustomer/Model/GetLoggedAsCustomerAdminId.php new file mode 100644 index 0000000000000..17af8a3b5c11f --- /dev/null +++ b/app/code/Magento/LoginAsCustomer/Model/GetLoggedAsCustomerAdminId.php @@ -0,0 +1,40 @@ +session = $session; + } + + /** + * @inheritdoc + */ + public function execute(): int + { + return (int)$this->session->getLoggedAsCustomerAdmindId(); + } +} diff --git a/app/code/Magento/LoginAsCustomer/Model/GetLoggedAsCustomerCustomerId.php b/app/code/Magento/LoginAsCustomer/Model/GetLoggedAsCustomerCustomerId.php new file mode 100644 index 0000000000000..9783b04a5a03f --- /dev/null +++ b/app/code/Magento/LoginAsCustomer/Model/GetLoggedAsCustomerCustomerId.php @@ -0,0 +1,40 @@ +session = $session; + } + + /** + * @inheritdoc + */ + public function execute(): int + { + return (int)$this->session->getLoggedAsCustomerCustomerId(); + } +} diff --git a/app/code/Magento/LoginAsCustomer/Model/SetLoggedAsCustomerAdminId.php b/app/code/Magento/LoginAsCustomer/Model/SetLoggedAsCustomerAdminId.php new file mode 100644 index 0000000000000..aa16dbcd4f808 --- /dev/null +++ b/app/code/Magento/LoginAsCustomer/Model/SetLoggedAsCustomerAdminId.php @@ -0,0 +1,40 @@ +session = $session; + } + + /** + * @inheritdoc + */ + public function execute(int $adminId): void + { + $this->session->setLoggedAsCustomerAdmindId($adminId); + } +} diff --git a/app/code/Magento/LoginAsCustomer/Model/SetLoggedAsCustomerCustomerId.php b/app/code/Magento/LoginAsCustomer/Model/SetLoggedAsCustomerCustomerId.php new file mode 100644 index 0000000000000..95e159bdeded3 --- /dev/null +++ b/app/code/Magento/LoginAsCustomer/Model/SetLoggedAsCustomerCustomerId.php @@ -0,0 +1,40 @@ +session = $session; + } + + /** + * @inheritdoc + */ + public function execute(int $customerId): void + { + $this->session->setLoggedAsCustomerCustomerId($customerId); + } +} diff --git a/app/code/Magento/LoginAsCustomer/Plugin/AdminLogoutPlugin.php b/app/code/Magento/LoginAsCustomer/Plugin/AdminLogoutPlugin.php index 244fed20c21e8..9b8567663578d 100644 --- a/app/code/Magento/LoginAsCustomer/Plugin/AdminLogoutPlugin.php +++ b/app/code/Magento/LoginAsCustomer/Plugin/AdminLogoutPlugin.php @@ -8,9 +8,9 @@ namespace Magento\LoginAsCustomer\Plugin; use Magento\Backend\Model\Auth; -use Magento\Backend\Model\Auth\Session as AuthSession; use Magento\LoginAsCustomerApi\Api\ConfigInterface; use Magento\LoginAsCustomerApi\Api\DeleteAuthenticationDataForUserInterface; +use Magento\LoginAsCustomerApi\Api\GetLoggedAsCustomerCustomerIdInterface; /** * Delete all Login as Customer sessions for logging out admin. @@ -19,11 +19,6 @@ */ class AdminLogoutPlugin { - /** - * @var AuthSession - */ - private $authSession; - /** * @var ConfigInterface */ @@ -35,18 +30,23 @@ class AdminLogoutPlugin private $deleteAuthenticationDataForUser; /** - * @param AuthSession $authSession + * @var GetLoggedAsCustomerCustomerIdInterface + */ + private $getLoggedAsCustomerCustomerId; + + /** * @param ConfigInterface $config * @param DeleteAuthenticationDataForUserInterface $deleteAuthenticationDataForUser + * @param GetLoggedAsCustomerCustomerIdInterface $getLoggedAsCustomerCustomerId */ public function __construct( - AuthSession $authSession, ConfigInterface $config, - DeleteAuthenticationDataForUserInterface $deleteAuthenticationDataForUser + DeleteAuthenticationDataForUserInterface $deleteAuthenticationDataForUser, + GetLoggedAsCustomerCustomerIdInterface $getLoggedAsCustomerCustomerId ) { - $this->authSession = $authSession; $this->config = $config; $this->deleteAuthenticationDataForUser = $deleteAuthenticationDataForUser; + $this->getLoggedAsCustomerCustomerId = $getLoggedAsCustomerCustomerId; } /** @@ -57,7 +57,7 @@ public function __construct( public function beforeLogout(Auth $subject): void { $user = $subject->getUser(); - $isLoggedAsCustomer = $this->authSession->getIsLoggedAsCustomer(); + $isLoggedAsCustomer = (bool)$this->getLoggedAsCustomerCustomerId->execute(); if ($this->config->isEnabled() && $user && $isLoggedAsCustomer) { $userId = (int)$user->getId(); $this->deleteAuthenticationDataForUser->execute($userId); diff --git a/app/code/Magento/LoginAsCustomer/etc/di.xml b/app/code/Magento/LoginAsCustomer/etc/di.xml index c0ba4901ba7b8..a1b4dfdb7ca27 100755 --- a/app/code/Magento/LoginAsCustomer/etc/di.xml +++ b/app/code/Magento/LoginAsCustomer/etc/di.xml @@ -13,6 +13,10 @@ + + + + diff --git a/app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php b/app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php index 70eef5347f8e3..4edd5491a0fee 100644 --- a/app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php +++ b/app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php @@ -23,6 +23,7 @@ use Magento\LoginAsCustomerApi\Api\Data\AuthenticationDataInterfaceFactory; use Magento\LoginAsCustomerApi\Api\DeleteAuthenticationDataForUserInterface; use Magento\LoginAsCustomerApi\Api\SaveAuthenticationDataInterface; +use Magento\LoginAsCustomerApi\Api\SetLoggedAsCustomerCustomerIdInterface; use Magento\Store\Model\StoreManagerInterface; /** @@ -80,6 +81,11 @@ class Login extends Action implements HttpGetActionInterface */ private $url; + /** + * @var SetLoggedAsCustomerCustomerIdInterface + */ + private $setLoggedAsCustomerCustomerId; + /** * @param Context $context * @param Session $authSession @@ -90,6 +96,9 @@ class Login extends Action implements HttpGetActionInterface * @param SaveAuthenticationDataInterface $saveAuthenticationData , * @param DeleteAuthenticationDataForUserInterface $deleteAuthenticationDataForUser * @param Url $url + * @param SetLoggedAsCustomerCustomerIdInterface $setLoggedAsCustomerCustomerId + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( Context $context, @@ -100,7 +109,8 @@ public function __construct( AuthenticationDataInterfaceFactory $authenticationDataFactory, SaveAuthenticationDataInterface $saveAuthenticationData, DeleteAuthenticationDataForUserInterface $deleteAuthenticationDataForUser, - Url $url + Url $url, + SetLoggedAsCustomerCustomerIdInterface $setLoggedAsCustomerCustomerId ) { parent::__construct($context); @@ -112,6 +122,7 @@ public function __construct( $this->saveAuthenticationData = $saveAuthenticationData; $this->deleteAuthenticationDataForUser = $deleteAuthenticationDataForUser; $this->url = $url; + $this->setLoggedAsCustomerCustomerId = $setLoggedAsCustomerCustomerId; } /** @@ -167,7 +178,7 @@ public function execute(): ResultInterface $this->deleteAuthenticationDataForUser->execute($userId); $secret = $this->saveAuthenticationData->execute($authenticationData); - $this->authSession->setIsLoggedAsCustomer(true); + $this->setLoggedAsCustomerCustomerId->execute($customerId); $redirectUrl = $this->getLoginProceedRedirectUrl($secret, $storeId); $resultRedirect->setUrl($redirectUrl); diff --git a/app/code/Magento/LoginAsCustomerApi/Api/GetLoggedAsCustomerAdminIdInterface.php b/app/code/Magento/LoginAsCustomerApi/Api/GetLoggedAsCustomerAdminIdInterface.php new file mode 100644 index 0000000000000..44b59c7810acc --- /dev/null +++ b/app/code/Magento/LoginAsCustomerApi/Api/GetLoggedAsCustomerAdminIdInterface.php @@ -0,0 +1,23 @@ +customerSession = $customerSession; $this->storeManager = $storeManager; + $this->getLoggedAsCustomerAdminId = $getLoggedAsCustomerAdminId; } /** @@ -49,12 +58,14 @@ public function __construct( */ public function getSectionData(): array { - if (!$this->customerSession->getCustomerId() || !$this->customerSession->getLoggedAsCustomerAdmindId()) { + $adminId = $this->getLoggedAsCustomerAdminId->execute(); + + if (!$adminId || !$this->customerSession->getCustomerId()) { return []; } return [ - 'adminUserId' => $this->customerSession->getLoggedAsCustomerAdmindId(), + 'adminUserId' => $adminId, 'websiteName' => $this->storeManager->getWebsite()->getName() ]; } diff --git a/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/InvalidateExpiredSessionPlugin.php b/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/InvalidateExpiredSessionPlugin.php index b68e871c5f955..9fe4b43032045 100644 --- a/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/InvalidateExpiredSessionPlugin.php +++ b/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/InvalidateExpiredSessionPlugin.php @@ -9,6 +9,7 @@ use Magento\Customer\Model\Session; use Magento\Framework\App\ActionInterface; use Magento\LoginAsCustomerApi\Api\ConfigInterface; +use Magento\LoginAsCustomerApi\Api\GetLoggedAsCustomerAdminIdInterface; use Magento\LoginAsCustomerApi\Api\IsLoginAsCustomerSessionActiveInterface; /** @@ -31,19 +32,27 @@ class InvalidateExpiredSessionPlugin */ private $isLoginAsCustomerSessionActive; + /** + * @var GetLoggedAsCustomerAdminIdInterface + */ + private $getLoggedAsCustomerAdminId; + /** * @param ConfigInterface $config * @param Session $session * @param IsLoginAsCustomerSessionActiveInterface $isLoginAsCustomerSessionActive + * @param GetLoggedAsCustomerAdminIdInterface $getLoggedAsCustomerAdminId */ public function __construct( ConfigInterface $config, Session $session, - IsLoginAsCustomerSessionActiveInterface $isLoginAsCustomerSessionActive + IsLoginAsCustomerSessionActiveInterface $isLoginAsCustomerSessionActive, + GetLoggedAsCustomerAdminIdInterface $getLoggedAsCustomerAdminId ) { $this->session = $session; $this->isLoginAsCustomerSessionActive = $isLoginAsCustomerSessionActive; $this->config = $config; + $this->getLoggedAsCustomerAdminId = $getLoggedAsCustomerAdminId; } /** @@ -57,7 +66,7 @@ public function __construct( public function beforeExecute(ActionInterface $subject) { if ($this->config->isEnabled()) { - $adminId = (int)$this->session->getLoggedAsCustomerAdmindId(); + $adminId = $this->getLoggedAsCustomerAdminId->execute(); $customerId = (int)$this->session->getCustomerId(); if ($adminId && $customerId) { if (!$this->isLoginAsCustomerSessionActive->execute($customerId, $adminId)) { diff --git a/app/code/Magento/LoginAsCustomerPageCache/Plugin/PageCache/Model/Config/DisablePageCacheIfNeededPlugin.php b/app/code/Magento/LoginAsCustomerPageCache/Plugin/PageCache/Model/Config/DisablePageCacheIfNeededPlugin.php index 6b36a0720ecb3..dabf8c62e1dee 100644 --- a/app/code/Magento/LoginAsCustomerPageCache/Plugin/PageCache/Model/Config/DisablePageCacheIfNeededPlugin.php +++ b/app/code/Magento/LoginAsCustomerPageCache/Plugin/PageCache/Model/Config/DisablePageCacheIfNeededPlugin.php @@ -7,8 +7,8 @@ namespace Magento\LoginAsCustomerPageCache\Plugin\PageCache\Model\Config; -use Magento\Customer\Model\Session; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\LoginAsCustomerApi\Api\GetLoggedAsCustomerAdminIdInterface; use Magento\PageCache\Model\Config; use Magento\Store\Model\ScopeInterface; @@ -27,20 +27,20 @@ class DisablePageCacheIfNeededPlugin private $scopeConfig; /** - * @var Session + * @var GetLoggedAsCustomerAdminIdInterface */ - private $customerSession; + private $getLoggedAsCustomerAdminId; /** * @param ScopeConfigInterface $scopeConfig - * @param Session $customerSession + * @param GetLoggedAsCustomerAdminIdInterface $getLoggedAsCustomerAdminId */ public function __construct( ScopeConfigInterface $scopeConfig, - Session $customerSession + GetLoggedAsCustomerAdminIdInterface $getLoggedAsCustomerAdminId ) { $this->scopeConfig = $scopeConfig; - $this->customerSession = $customerSession; + $this->getLoggedAsCustomerAdminId = $getLoggedAsCustomerAdminId; } /** @@ -58,7 +58,7 @@ public function afterIsEnabled(Config $subject, $isEnabled): bool 'login_as_customer/general/disable_page_cache', ScopeInterface::SCOPE_STORE ); - $adminId = $this->customerSession->getLoggedAsCustomerAdmindId(); + $adminId = $this->getLoggedAsCustomerAdminId->execute(); if ($disable && $adminId) { $isEnabled = false; } diff --git a/app/code/Magento/LoginAsCustomerSales/Plugin/FrontAddCommentOnOrderPlacementPlugin.php b/app/code/Magento/LoginAsCustomerSales/Plugin/FrontAddCommentOnOrderPlacementPlugin.php index dc7b295f61c4d..87ffe81998d58 100644 --- a/app/code/Magento/LoginAsCustomerSales/Plugin/FrontAddCommentOnOrderPlacementPlugin.php +++ b/app/code/Magento/LoginAsCustomerSales/Plugin/FrontAddCommentOnOrderPlacementPlugin.php @@ -7,7 +7,7 @@ namespace Magento\LoginAsCustomerSales\Plugin; -use Magento\Customer\Model\Session; +use Magento\LoginAsCustomerApi\Api\GetLoggedAsCustomerAdminIdInterface; use Magento\Sales\Model\Order; use Magento\User\Model\UserFactory; @@ -19,25 +19,25 @@ class FrontAddCommentOnOrderPlacementPlugin { /** - * @var Session + * @var UserFactory */ - private $customerSession; + private $userFactory; /** - * @var UserFactory + * @var GetLoggedAsCustomerAdminIdInterface */ - private $userFactory; + private $getLoggedAsCustomerAdminId; /** - * @param Session $session * @param UserFactory $userFactory + * @param GetLoggedAsCustomerAdminIdInterface $getLoggedAsCustomerAdminId */ public function __construct( - Session $session, - UserFactory $userFactory + UserFactory $userFactory, + GetLoggedAsCustomerAdminIdInterface $getLoggedAsCustomerAdminId ) { - $this->customerSession = $session; $this->userFactory = $userFactory; + $this->getLoggedAsCustomerAdminId = $getLoggedAsCustomerAdminId; } /** @@ -49,7 +49,7 @@ public function __construct( */ public function afterPlace(Order $subject, Order $result): Order { - $adminId = $this->customerSession->getLoggedAsCustomerAdmindId(); + $adminId = $this->getLoggedAsCustomerAdminId->execute(); if ($adminId) { $adminUser = $this->userFactory->create()->load($adminId); $subject->addCommentToStatusHistory( From d9c02ed6db4d43427366f8356a2b59b64a37284f Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Tue, 23 Jun 2020 17:02:10 +0300 Subject: [PATCH 02/10] magento/magento2-login-as-customer#144: "Login as Customer" functionality should be enabled by default. --- .../Magento/LoginAsCustomer/etc/config.xml | 2 +- .../ViewModel/Configuration.php | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/LoginAsCustomer/etc/config.xml b/app/code/Magento/LoginAsCustomer/etc/config.xml index 936ae1ff2f05d..7e39cc39145eb 100644 --- a/app/code/Magento/LoginAsCustomer/etc/config.xml +++ b/app/code/Magento/LoginAsCustomer/etc/config.xml @@ -10,7 +10,7 @@ - 0 + 1 0 60 diff --git a/app/code/Magento/LoginAsCustomerFrontendUi/ViewModel/Configuration.php b/app/code/Magento/LoginAsCustomerFrontendUi/ViewModel/Configuration.php index 7d8738d06f54f..5de790968c5e9 100644 --- a/app/code/Magento/LoginAsCustomerFrontendUi/ViewModel/Configuration.php +++ b/app/code/Magento/LoginAsCustomerFrontendUi/ViewModel/Configuration.php @@ -8,7 +8,9 @@ namespace Magento\LoginAsCustomerFrontendUi\ViewModel; use Magento\Customer\Model\Context; +use Magento\Framework\App\Http\Context as HttpContext; use Magento\LoginAsCustomerApi\Api\ConfigInterface; +use Magento\LoginAsCustomerApi\Api\GetLoggedAsCustomerAdminIdInterface; /** * View model to get extension configuration in the template @@ -21,20 +23,28 @@ class Configuration implements \Magento\Framework\View\Element\Block\ArgumentInt private $config; /** - * @var \Magento\Framework\App\Http\Context + * @var HttpContext */ private $httpContext; + /** + * @var GetLoggedAsCustomerAdminIdInterface + */ + private $getLoggedAsCustomerAdminId; + /** * @param ConfigInterface $config - * @param \Magento\Framework\App\Http\Context $httpContext + * @param HttpContext $httpContext + * @param GetLoggedAsCustomerAdminIdInterface $getLoggedAsCustomerAdminId */ public function __construct( ConfigInterface $config, - \Magento\Framework\App\Http\Context $httpContext + HttpContext $httpContext, + GetLoggedAsCustomerAdminIdInterface $getLoggedAsCustomerAdminId ) { $this->config = $config; $this->httpContext = $httpContext; + $this->getLoggedAsCustomerAdminId = $getLoggedAsCustomerAdminId; } /** @@ -44,7 +54,7 @@ public function __construct( */ public function isEnabled(): bool { - return $this->config->isEnabled() && $this->isLoggedIn(); + return $this->config->isEnabled() && $this->isLoggedIn() && $this->getLoggedAsCustomerAdminId->execute(); } /** From 07f03fe8a728aad4ebe807c30bdd68b9007917ea Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Wed, 24 Jun 2020 16:25:57 +0300 Subject: [PATCH 03/10] magento/magento2-login-as-customer#144: Banner is not shown on Category page if Disable Page Cache For Admin User = No. --- .../KeepLoginAsCustomerSessionDataPlugin.php | 71 +++++++++++++++++++ .../etc/frontend/di.xml | 4 ++ 2 files changed, 75 insertions(+) create mode 100644 app/code/Magento/LoginAsCustomerFrontendUi/Plugin/KeepLoginAsCustomerSessionDataPlugin.php diff --git a/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/KeepLoginAsCustomerSessionDataPlugin.php b/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/KeepLoginAsCustomerSessionDataPlugin.php new file mode 100644 index 0000000000000..2252786d1a408 --- /dev/null +++ b/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/KeepLoginAsCustomerSessionDataPlugin.php @@ -0,0 +1,71 @@ +config = $config; + $this->getLoggedAsCustomerAdminId = $getLoggedAsCustomerAdminId; + $this->setLoggedAsCustomerAdminId = $setLoggedAsCustomerAdminId; + } + + /** + * Keep adminId in customer session if session data is cleared. + * + * @param SessionManagerInterface $subject + * @param \Closure $proceed + * @return SessionManagerInterface + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function aroundClearStorage( + SessionManagerInterface $subject, + \Closure $proceed + ): SessionManagerInterface { + $enabled = $this->config->isEnabled(); + $adminId = $enabled ? $this->getLoggedAsCustomerAdminId->execute() : null; + $result = $proceed(); + if ($enabled && $adminId) { + $this->setLoggedAsCustomerAdminId->execute($adminId); + } + + return $result; + } +} diff --git a/app/code/Magento/LoginAsCustomerFrontendUi/etc/frontend/di.xml b/app/code/Magento/LoginAsCustomerFrontendUi/etc/frontend/di.xml index 2204402b7dd30..bff511b6bb6e6 100644 --- a/app/code/Magento/LoginAsCustomerFrontendUi/etc/frontend/di.xml +++ b/app/code/Magento/LoginAsCustomerFrontendUi/etc/frontend/di.xml @@ -17,4 +17,8 @@ + + + From 75ac691828891604d7a1e1a6f13d3e0b1de296bd Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Thu, 2 Jul 2020 16:09:24 +0300 Subject: [PATCH 04/10] magento/magento2-login-as-customer#144: Banner is not shown on Category page if Disable Page Cache For Admin User = No - updated. --- .../LoginAsCustomer/Model/AuthenticateCustomerBySecret.php | 5 +++-- .../Controller/Adminhtml/Login/Login.php | 5 +++-- .../Api/GetLoggedAsCustomerAdminIdInterface.php | 2 -- .../Api/GetLoggedAsCustomerCustomerIdInterface.php | 2 -- .../Api/SetLoggedAsCustomerAdminIdInterface.php | 2 -- .../Api/SetLoggedAsCustomerCustomerIdInterface.php | 2 -- .../CustomerData/LoginAsCustomerUi.php | 5 +++-- .../Plugin/KeepLoginAsCustomerSessionDataPlugin.php | 2 ++ .../LoginAsCustomerFrontendUi/ViewModel/Configuration.php | 5 +++-- 9 files changed, 14 insertions(+), 16 deletions(-) diff --git a/app/code/Magento/LoginAsCustomer/Model/AuthenticateCustomerBySecret.php b/app/code/Magento/LoginAsCustomer/Model/AuthenticateCustomerBySecret.php index a27c1c43ad965..a445d4e55c2fc 100644 --- a/app/code/Magento/LoginAsCustomer/Model/AuthenticateCustomerBySecret.php +++ b/app/code/Magento/LoginAsCustomer/Model/AuthenticateCustomerBySecret.php @@ -8,6 +8,7 @@ namespace Magento\LoginAsCustomer\Model; use Magento\Customer\Model\Session; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\LocalizedException; use Magento\LoginAsCustomerApi\Api\AuthenticateCustomerBySecretInterface; use Magento\LoginAsCustomerApi\Api\GetAuthenticationDataBySecretInterface; @@ -43,11 +44,11 @@ class AuthenticateCustomerBySecret implements AuthenticateCustomerBySecretInterf public function __construct( GetAuthenticationDataBySecretInterface $getAuthenticationDataBySecret, Session $customerSession, - SetLoggedAsCustomerAdminIdInterface $setLoggedAsCustomerAdminId + ?SetLoggedAsCustomerAdminIdInterface $setLoggedAsCustomerAdminId = null ) { $this->getAuthenticationDataBySecret = $getAuthenticationDataBySecret; $this->customerSession = $customerSession; - $this->setLoggedAsCustomerAdminId = $setLoggedAsCustomerAdminId; + $this->setLoggedAsCustomerAdminId = $setLoggedAsCustomerAdminId ?? ObjectManager::getInstance()->get(SetLoggedAsCustomerAdminIdInterface::class); } /** diff --git a/app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php b/app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php index 4edd5491a0fee..703fb98a93077 100644 --- a/app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php +++ b/app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php @@ -12,6 +12,7 @@ use Magento\Backend\Model\Auth\Session; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Controller\ResultInterface; @@ -110,7 +111,7 @@ public function __construct( SaveAuthenticationDataInterface $saveAuthenticationData, DeleteAuthenticationDataForUserInterface $deleteAuthenticationDataForUser, Url $url, - SetLoggedAsCustomerCustomerIdInterface $setLoggedAsCustomerCustomerId + ?SetLoggedAsCustomerCustomerIdInterface $setLoggedAsCustomerCustomerId = null ) { parent::__construct($context); @@ -122,7 +123,7 @@ public function __construct( $this->saveAuthenticationData = $saveAuthenticationData; $this->deleteAuthenticationDataForUser = $deleteAuthenticationDataForUser; $this->url = $url; - $this->setLoggedAsCustomerCustomerId = $setLoggedAsCustomerCustomerId; + $this->setLoggedAsCustomerCustomerId = $setLoggedAsCustomerCustomerId ?? ObjectManager::getInstance()->get(SetLoggedAsCustomerCustomerIdInterface::class); } /** diff --git a/app/code/Magento/LoginAsCustomerApi/Api/GetLoggedAsCustomerAdminIdInterface.php b/app/code/Magento/LoginAsCustomerApi/Api/GetLoggedAsCustomerAdminIdInterface.php index 44b59c7810acc..49c0f796be006 100644 --- a/app/code/Magento/LoginAsCustomerApi/Api/GetLoggedAsCustomerAdminIdInterface.php +++ b/app/code/Magento/LoginAsCustomerApi/Api/GetLoggedAsCustomerAdminIdInterface.php @@ -9,8 +9,6 @@ /** * Get id of Admin logged as Customer. - * - * @api */ interface GetLoggedAsCustomerAdminIdInterface { diff --git a/app/code/Magento/LoginAsCustomerApi/Api/GetLoggedAsCustomerCustomerIdInterface.php b/app/code/Magento/LoginAsCustomerApi/Api/GetLoggedAsCustomerCustomerIdInterface.php index 1d12d6551a2ff..047061b3edd69 100644 --- a/app/code/Magento/LoginAsCustomerApi/Api/GetLoggedAsCustomerCustomerIdInterface.php +++ b/app/code/Magento/LoginAsCustomerApi/Api/GetLoggedAsCustomerCustomerIdInterface.php @@ -9,8 +9,6 @@ /** * Get id of Customer Admin is logged as. - * - * @api */ interface GetLoggedAsCustomerCustomerIdInterface { diff --git a/app/code/Magento/LoginAsCustomerApi/Api/SetLoggedAsCustomerAdminIdInterface.php b/app/code/Magento/LoginAsCustomerApi/Api/SetLoggedAsCustomerAdminIdInterface.php index 531a21496901e..b921c2fc6e8d3 100644 --- a/app/code/Magento/LoginAsCustomerApi/Api/SetLoggedAsCustomerAdminIdInterface.php +++ b/app/code/Magento/LoginAsCustomerApi/Api/SetLoggedAsCustomerAdminIdInterface.php @@ -9,8 +9,6 @@ /** * Set id of Admin logged as Customer. - * - * @api */ interface SetLoggedAsCustomerAdminIdInterface { diff --git a/app/code/Magento/LoginAsCustomerApi/Api/SetLoggedAsCustomerCustomerIdInterface.php b/app/code/Magento/LoginAsCustomerApi/Api/SetLoggedAsCustomerCustomerIdInterface.php index a77300528ba72..265ae1aa36c45 100644 --- a/app/code/Magento/LoginAsCustomerApi/Api/SetLoggedAsCustomerCustomerIdInterface.php +++ b/app/code/Magento/LoginAsCustomerApi/Api/SetLoggedAsCustomerCustomerIdInterface.php @@ -9,8 +9,6 @@ /** * Set id of Customer Admin is logged as. - * - * @api */ interface SetLoggedAsCustomerCustomerIdInterface { diff --git a/app/code/Magento/LoginAsCustomerFrontendUi/CustomerData/LoginAsCustomerUi.php b/app/code/Magento/LoginAsCustomerFrontendUi/CustomerData/LoginAsCustomerUi.php index 762061ac5f364..78ac010c965e3 100644 --- a/app/code/Magento/LoginAsCustomerFrontendUi/CustomerData/LoginAsCustomerUi.php +++ b/app/code/Magento/LoginAsCustomerFrontendUi/CustomerData/LoginAsCustomerUi.php @@ -9,6 +9,7 @@ use Magento\Customer\CustomerData\SectionSourceInterface; use Magento\Customer\Model\Session; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\LocalizedException; use Magento\LoginAsCustomerApi\Api\GetLoggedAsCustomerAdminIdInterface; use Magento\Store\Model\StoreManagerInterface; @@ -43,11 +44,11 @@ class LoginAsCustomerUi implements SectionSourceInterface public function __construct( Session $customerSession, StoreManagerInterface $storeManager, - GetLoggedAsCustomerAdminIdInterface $getLoggedAsCustomerAdminId + ?GetLoggedAsCustomerAdminIdInterface $getLoggedAsCustomerAdminId = null ) { $this->customerSession = $customerSession; $this->storeManager = $storeManager; - $this->getLoggedAsCustomerAdminId = $getLoggedAsCustomerAdminId; + $this->getLoggedAsCustomerAdminId = $getLoggedAsCustomerAdminId ?? ObjectManager::getInstance()->get(GetLoggedAsCustomerAdminIdInterface::class); } /** diff --git a/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/KeepLoginAsCustomerSessionDataPlugin.php b/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/KeepLoginAsCustomerSessionDataPlugin.php index 2252786d1a408..9519f3a54077b 100644 --- a/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/KeepLoginAsCustomerSessionDataPlugin.php +++ b/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/KeepLoginAsCustomerSessionDataPlugin.php @@ -4,6 +4,8 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\LoginAsCustomerFrontendUi\Plugin; use Magento\Framework\Session\SessionManagerInterface; diff --git a/app/code/Magento/LoginAsCustomerFrontendUi/ViewModel/Configuration.php b/app/code/Magento/LoginAsCustomerFrontendUi/ViewModel/Configuration.php index 5de790968c5e9..e7a5cd146410e 100644 --- a/app/code/Magento/LoginAsCustomerFrontendUi/ViewModel/Configuration.php +++ b/app/code/Magento/LoginAsCustomerFrontendUi/ViewModel/Configuration.php @@ -9,6 +9,7 @@ use Magento\Customer\Model\Context; use Magento\Framework\App\Http\Context as HttpContext; +use Magento\Framework\App\ObjectManager; use Magento\LoginAsCustomerApi\Api\ConfigInterface; use Magento\LoginAsCustomerApi\Api\GetLoggedAsCustomerAdminIdInterface; @@ -40,11 +41,11 @@ class Configuration implements \Magento\Framework\View\Element\Block\ArgumentInt public function __construct( ConfigInterface $config, HttpContext $httpContext, - GetLoggedAsCustomerAdminIdInterface $getLoggedAsCustomerAdminId + ?GetLoggedAsCustomerAdminIdInterface $getLoggedAsCustomerAdminId = null ) { $this->config = $config; $this->httpContext = $httpContext; - $this->getLoggedAsCustomerAdminId = $getLoggedAsCustomerAdminId; + $this->getLoggedAsCustomerAdminId = $getLoggedAsCustomerAdminId ?? ObjectManager::getInstance()->get(GetLoggedAsCustomerAdminIdInterface::class); } /** From 76d86d9e00dc535e60e5b920e310c9e38a8fc34d Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Fri, 3 Jul 2020 11:41:15 +0300 Subject: [PATCH 05/10] magento/magento2-login-as-customer#187: Move frontend-specific code (such as session-related) to LoginAsCustomerFrontendUi module. --- app/code/Magento/LoginAsCustomer/etc/di.xml | 1 - .../Model/AuthenticateCustomerBySecret.php | 2 +- app/code/Magento/LoginAsCustomerFrontendUi/etc/frontend/di.xml | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) rename app/code/Magento/{LoginAsCustomer => LoginAsCustomerFrontendUi}/Model/AuthenticateCustomerBySecret.php (97%) diff --git a/app/code/Magento/LoginAsCustomer/etc/di.xml b/app/code/Magento/LoginAsCustomer/etc/di.xml index c0ba4901ba7b8..c3cb05ea0c433 100755 --- a/app/code/Magento/LoginAsCustomer/etc/di.xml +++ b/app/code/Magento/LoginAsCustomer/etc/di.xml @@ -9,7 +9,6 @@ - diff --git a/app/code/Magento/LoginAsCustomer/Model/AuthenticateCustomerBySecret.php b/app/code/Magento/LoginAsCustomerFrontendUi/Model/AuthenticateCustomerBySecret.php similarity index 97% rename from app/code/Magento/LoginAsCustomer/Model/AuthenticateCustomerBySecret.php rename to app/code/Magento/LoginAsCustomerFrontendUi/Model/AuthenticateCustomerBySecret.php index a728f4c3a4393..59251be8012c1 100644 --- a/app/code/Magento/LoginAsCustomer/Model/AuthenticateCustomerBySecret.php +++ b/app/code/Magento/LoginAsCustomerFrontendUi/Model/AuthenticateCustomerBySecret.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magento\LoginAsCustomer\Model; +namespace Magento\LoginAsCustomerFrontendUi\Model; use Magento\Customer\Model\Session; use Magento\Framework\Exception\LocalizedException; diff --git a/app/code/Magento/LoginAsCustomerFrontendUi/etc/frontend/di.xml b/app/code/Magento/LoginAsCustomerFrontendUi/etc/frontend/di.xml index 2204402b7dd30..2cdde68397700 100644 --- a/app/code/Magento/LoginAsCustomerFrontendUi/etc/frontend/di.xml +++ b/app/code/Magento/LoginAsCustomerFrontendUi/etc/frontend/di.xml @@ -6,6 +6,7 @@ */ --> + From 86ec81c9567dced0bc6a284b3dca76809c748f33 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Fri, 3 Jul 2020 16:28:51 +0300 Subject: [PATCH 06/10] magento/magento2-login-as-customer#188: Introduce Login as Customer "is enabled" check extensibility. --- ...LoginAsCustomerEnabledForCustomerChain.php | 66 ++++++++++++++++ ...oginAsCustomerEnabledForCustomerResult.php | 53 +++++++++++++ .../IsLoginAsCustomerEnabledResolver.php | 54 +++++++++++++ app/code/Magento/LoginAsCustomer/etc/di.xml | 32 ++++++-- .../Controller/Adminhtml/Login/Login.php | 32 ++++++-- .../Plugin/Button/ToolbarPlugin.php | 67 +++++++++------- .../Component/Button/DataProvider.php | 79 +++++++++++++++++++ .../Control/LoginAsCustomerButton.php | 42 +++------- .../etc/adminhtml/di.xml | 12 ++- .../Magento/LoginAsCustomerAdminUi/etc/di.xml | 31 ++++++++ ...tomerEnabledForCustomerResultInterface.php | 37 +++++++++ ...nAsCustomerEnabledForCustomerInterface.php | 26 ++++++ 12 files changed, 459 insertions(+), 72 deletions(-) create mode 100644 app/code/Magento/LoginAsCustomer/Model/IsLoginAsCustomerEnabledForCustomerChain.php create mode 100644 app/code/Magento/LoginAsCustomer/Model/IsLoginAsCustomerEnabledForCustomerResult.php create mode 100644 app/code/Magento/LoginAsCustomer/Model/Resolver/IsLoginAsCustomerEnabledResolver.php create mode 100644 app/code/Magento/LoginAsCustomerAdminUi/Ui/Customer/Component/Button/DataProvider.php create mode 100644 app/code/Magento/LoginAsCustomerAdminUi/etc/di.xml create mode 100644 app/code/Magento/LoginAsCustomerApi/Api/Data/IsLoginAsCustomerEnabledForCustomerResultInterface.php create mode 100644 app/code/Magento/LoginAsCustomerApi/Api/IsLoginAsCustomerEnabledForCustomerInterface.php diff --git a/app/code/Magento/LoginAsCustomer/Model/IsLoginAsCustomerEnabledForCustomerChain.php b/app/code/Magento/LoginAsCustomer/Model/IsLoginAsCustomerEnabledForCustomerChain.php new file mode 100644 index 0000000000000..6937a11eb3b58 --- /dev/null +++ b/app/code/Magento/LoginAsCustomer/Model/IsLoginAsCustomerEnabledForCustomerChain.php @@ -0,0 +1,66 @@ +config = $config; + $this->resultFactory = $resultFactory; + $this->resolvers = $resolvers; + } + + /** + * @inheritdoc + */ + public function execute(int $customerId): IsLoginAsCustomerEnabledForCustomerResultInterface + { + $messages = [[]]; + /** @var IsLoginAsCustomerEnabledForCustomerResultInterface $resolver */ + foreach ($this->resolvers as $resolver) { + $resolverResult = $resolver->execute($customerId); + if (!$resolverResult->isEnabled()) { + $messages[] = $resolverResult->getMessages(); + } + } + + return $this->resultFactory->create(['messages' => array_merge(...$messages)]); + } +} diff --git a/app/code/Magento/LoginAsCustomer/Model/IsLoginAsCustomerEnabledForCustomerResult.php b/app/code/Magento/LoginAsCustomer/Model/IsLoginAsCustomerEnabledForCustomerResult.php new file mode 100644 index 0000000000000..0d2af8669777c --- /dev/null +++ b/app/code/Magento/LoginAsCustomer/Model/IsLoginAsCustomerEnabledForCustomerResult.php @@ -0,0 +1,53 @@ +messages = $messages; + } + + /** + * @inheritdoc + */ + public function isEnabled(): bool + { + return empty($this->messages); + } + + /** + * @inheritdoc + */ + public function getMessages(): array + { + return $this->messages; + } + + /** + * @inheritdoc + */ + public function setMessages(array $messages): void + { + $this->messages = $messages; + } +} diff --git a/app/code/Magento/LoginAsCustomer/Model/Resolver/IsLoginAsCustomerEnabledResolver.php b/app/code/Magento/LoginAsCustomer/Model/Resolver/IsLoginAsCustomerEnabledResolver.php new file mode 100644 index 0000000000000..de16a798983c0 --- /dev/null +++ b/app/code/Magento/LoginAsCustomer/Model/Resolver/IsLoginAsCustomerEnabledResolver.php @@ -0,0 +1,54 @@ +config = $config; + $this->resultFactory = $resultFactory; + } + + /** + * @inheritdoc + */ + public function execute(int $customerId): IsLoginAsCustomerEnabledForCustomerResultInterface + { + $messages = []; + if (!$this->config->isEnabled()) { + $messages[] = __('Login as Customer is disabled.'); + } + + return $this->resultFactory->create(['messages' => $messages]); + } +} diff --git a/app/code/Magento/LoginAsCustomer/etc/di.xml b/app/code/Magento/LoginAsCustomer/etc/di.xml index c0ba4901ba7b8..d4728bc0c8f42 100755 --- a/app/code/Magento/LoginAsCustomer/etc/di.xml +++ b/app/code/Magento/LoginAsCustomer/etc/di.xml @@ -5,14 +5,32 @@ * See COPYING.txt for license details. */ --> - - - - - - + + + + + + - + + + + + + + Magento\LoginAsCustomer\Model\Resolver\IsLoginAsCustomerEnabledResolver + + + + diff --git a/app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php b/app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php index 70eef5347f8e3..27189cb2682e9 100644 --- a/app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php +++ b/app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php @@ -12,6 +12,7 @@ use Magento\Backend\Model\Auth\Session; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Controller\ResultInterface; @@ -22,6 +23,7 @@ use Magento\LoginAsCustomerApi\Api\Data\AuthenticationDataInterface; use Magento\LoginAsCustomerApi\Api\Data\AuthenticationDataInterfaceFactory; use Magento\LoginAsCustomerApi\Api\DeleteAuthenticationDataForUserInterface; +use Magento\LoginAsCustomerApi\Api\IsLoginAsCustomerEnabledForCustomerInterface; use Magento\LoginAsCustomerApi\Api\SaveAuthenticationDataInterface; use Magento\Store\Model\StoreManagerInterface; @@ -80,6 +82,11 @@ class Login extends Action implements HttpGetActionInterface */ private $url; + /** + * @var IsLoginAsCustomerEnabledForCustomerInterface + */ + private $isLoginAsCustomerEnabled; + /** * @param Context $context * @param Session $authSession @@ -87,9 +94,11 @@ class Login extends Action implements HttpGetActionInterface * @param CustomerRepositoryInterface $customerRepository * @param ConfigInterface $config * @param AuthenticationDataInterfaceFactory $authenticationDataFactory - * @param SaveAuthenticationDataInterface $saveAuthenticationData , + * @param SaveAuthenticationDataInterface $saveAuthenticationData * @param DeleteAuthenticationDataForUserInterface $deleteAuthenticationDataForUser * @param Url $url + * @param IsLoginAsCustomerEnabledForCustomerInterface $isLoginAsCustomerEnabled + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( Context $context, @@ -100,7 +109,8 @@ public function __construct( AuthenticationDataInterfaceFactory $authenticationDataFactory, SaveAuthenticationDataInterface $saveAuthenticationData, DeleteAuthenticationDataForUserInterface $deleteAuthenticationDataForUser, - Url $url + Url $url, + ?IsLoginAsCustomerEnabledForCustomerInterface $isLoginAsCustomerEnabled = null ) { parent::__construct($context); @@ -112,6 +122,8 @@ public function __construct( $this->saveAuthenticationData = $saveAuthenticationData; $this->deleteAuthenticationDataForUser = $deleteAuthenticationDataForUser; $this->url = $url; + $this->isLoginAsCustomerEnabled = $isLoginAsCustomerEnabled + ?? ObjectManager::getInstance()->get(IsLoginAsCustomerEnabledForCustomerInterface::class); } /** @@ -126,20 +138,24 @@ public function execute(): ResultInterface /** @var Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - if (!$this->config->isEnabled()) { - $this->messageManager->addErrorMessage(__('Login as Customer is disabled.')); - return $resultRedirect->setPath('customer/index/index'); - } - $customerId = (int)$this->_request->getParam('customer_id'); if (!$customerId) { $customerId = (int)$this->_request->getParam('entity_id'); } + $isLoginAsCustomerEnabled = $this->isLoginAsCustomerEnabled->execute($customerId); + if (!$isLoginAsCustomerEnabled->isEnabled()) { + foreach ($isLoginAsCustomerEnabled->getMessages() as $message) { + $this->messageManager->addErrorMessage(__($message)); + } + + return $resultRedirect->setPath('customer/index/index'); + } + try { $customer = $this->customerRepository->getById($customerId); } catch (NoSuchEntityException $e) { - $this->messageManager->addErrorMessage(__('Customer with this ID are no longer exist.')); + $this->messageManager->addErrorMessage('Customer with this ID are no longer exist.'); return $resultRedirect->setPath('customer/index/index'); } diff --git a/app/code/Magento/LoginAsCustomerAdminUi/Plugin/Button/ToolbarPlugin.php b/app/code/Magento/LoginAsCustomerAdminUi/Plugin/Button/ToolbarPlugin.php index 89ee2791e38af..3516a181b5dde 100644 --- a/app/code/Magento/LoginAsCustomerAdminUi/Plugin/Button/ToolbarPlugin.php +++ b/app/code/Magento/LoginAsCustomerAdminUi/Plugin/Button/ToolbarPlugin.php @@ -9,9 +9,10 @@ use Magento\Backend\Block\Widget\Button\ButtonList; use Magento\Backend\Block\Widget\Button\Toolbar; -use Magento\Framework\View\Element\AbstractBlock; -use Magento\Framework\Escaper; use Magento\Framework\AuthorizationInterface; +use Magento\Framework\Escaper; +use Magento\Framework\View\Element\AbstractBlock; +use Magento\LoginAsCustomerAdminUi\Ui\Customer\Component\Button\DataProvider; use Magento\LoginAsCustomerApi\Api\ConfigInterface; /** @@ -34,20 +35,28 @@ class ToolbarPlugin */ private $config; + /** + * @var DataProvider + */ + private $dataProvider; + /** * ToolbarPlugin constructor. * @param AuthorizationInterface $authorization * @param ConfigInterface $config * @param Escaper $escaper + * @param DataProvider $dataProvider */ public function __construct( AuthorizationInterface $authorization, ConfigInterface $config, - Escaper $escaper + Escaper $escaper, + DataProvider $dataProvider ) { $this->authorization = $authorization; $this->config = $config; $this->escaper = $escaper; + $this->dataProvider = $dataProvider; } /** @@ -62,10 +71,35 @@ public function beforePushButtons( Toolbar $subject, AbstractBlock $context, ButtonList $buttonList - ):void { - $order = false; + ): void { $nameInLayout = $context->getNameInLayout(); + $order = $this->getOrder($nameInLayout, $context); + if ($order + && !empty($order['customer_id']) + && $this->config->isEnabled() + && $this->authorization->isAllowed('Magento_LoginAsCustomer::login_button') + ) { + $customerId = (int)$order['customer_id']; + $buttonList->add( + 'guest_to_customer', + $this->dataProvider->getData($customerId), + -1 + ); + } + } + + /** + * Extract order data from context. + * + * @param string $nameInLayout + * @param AbstractBlock $context + * @return array|null + */ + private function getOrder(string $nameInLayout, AbstractBlock $context) + { + $order = null; + if ('sales_order_edit' == $nameInLayout) { $order = $context->getOrder(); } elseif ('sales_invoice_view' == $nameInLayout) { @@ -75,28 +109,7 @@ public function beforePushButtons( } elseif ('sales_creditmemo_view' == $nameInLayout) { $order = $context->getCreditmemo()->getOrder(); } - if ($order) { - $isAllowed = $this->authorization->isAllowed('Magento_LoginAsCustomer::login_button'); - $isEnabled = $this->config->isEnabled(); - if ($isAllowed && $isEnabled) { - if (!empty($order['customer_id'])) { - $buttonUrl = $context->getUrl('loginascustomer/login/login', [ - 'customer_id' => $order['customer_id'] - ]); - $buttonList->add( - 'guest_to_customer', - [ - 'label' => __('Login as Customer'), - 'onclick' => 'window.lacConfirmationPopup("' - . $this->escaper->escapeHtml($this->escaper->escapeJs($buttonUrl)) - . '")', - 'class' => 'reset' - ], - -1 - ); - } - } - } + return $order; } } diff --git a/app/code/Magento/LoginAsCustomerAdminUi/Ui/Customer/Component/Button/DataProvider.php b/app/code/Magento/LoginAsCustomerAdminUi/Ui/Customer/Component/Button/DataProvider.php new file mode 100644 index 0000000000000..19db8c67f945e --- /dev/null +++ b/app/code/Magento/LoginAsCustomerAdminUi/Ui/Customer/Component/Button/DataProvider.php @@ -0,0 +1,79 @@ +escaper = $escaper; + $this->urlBuilder = $urlBuilder; + $this->data = $data; + } + + /** + * Get data for Login as Customer button. + * + * @param int $customerId + * @return array + */ + public function getData(int $customerId): array + { + $buttonData = [ + 'on_click' => 'window.lacConfirmationPopup("' + . $this->escaper->escapeHtml($this->escaper->escapeJs($this->getLoginUrl($customerId))) + . '")', + ]; + + return array_merge_recursive($buttonData, $this->data); + } + + /** + * Get Login as Customer login url. + * + * @param int $customerId + * @return string + */ + private function getLoginUrl(int $customerId): string + { + return $this->urlBuilder->getUrl('loginascustomer/login/login', ['customer_id' => $customerId]); + } +} diff --git a/app/code/Magento/LoginAsCustomerAdminUi/Ui/Customer/Component/Control/LoginAsCustomerButton.php b/app/code/Magento/LoginAsCustomerAdminUi/Ui/Customer/Component/Control/LoginAsCustomerButton.php index d900641c131a3..ab43fca3d447e 100644 --- a/app/code/Magento/LoginAsCustomerAdminUi/Ui/Customer/Component/Control/LoginAsCustomerButton.php +++ b/app/code/Magento/LoginAsCustomerAdminUi/Ui/Customer/Component/Control/LoginAsCustomerButton.php @@ -7,12 +7,13 @@ namespace Magento\LoginAsCustomerAdminUi\Ui\Customer\Component\Control; -use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface; -use Magento\Framework\AuthorizationInterface; -use Magento\Framework\Escaper; -use Magento\Framework\Registry; use Magento\Backend\Block\Widget\Context; use Magento\Customer\Block\Adminhtml\Edit\GenericButton; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\AuthorizationInterface; +use Magento\Framework\Registry; +use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface; +use Magento\LoginAsCustomerAdminUi\Ui\Customer\Component\Button\DataProvider; use Magento\LoginAsCustomerApi\Api\ConfigInterface; /** @@ -31,26 +32,26 @@ class LoginAsCustomerButton extends GenericButton implements ButtonProviderInter private $config; /** - * Escaper - * - * @var Escaper + * @var DataProvider */ - private $escaper; + private $dataProvider; /** * @param Context $context * @param Registry $registry * @param ConfigInterface $config + * @param DataProvider $dataProvider */ public function __construct( Context $context, Registry $registry, - ConfigInterface $config + ConfigInterface $config, + ?DataProvider $dataProvider = null ) { parent::__construct($context, $registry); $this->authorization = $context->getAuthorization(); $this->config = $config; - $this->escaper = $context->getEscaper(); + $this->dataProvider = $dataProvider ?? ObjectManager::getInstance()->get(DataProvider::class); } /** @@ -58,31 +59,14 @@ public function __construct( */ public function getButtonData(): array { - $customerId = $this->getCustomerId(); + $customerId = (int)$this->getCustomerId(); $data = []; $isAllowed = $customerId && $this->authorization->isAllowed('Magento_LoginAsCustomer::login_button'); $isEnabled = $this->config->isEnabled(); if ($isAllowed && $isEnabled) { - $data = [ - 'label' => __('Login as Customer'), - 'class' => 'login login-button', - 'on_click' => 'window.lacConfirmationPopup("' - . $this->escaper->escapeHtml($this->escaper->escapeJs($this->getLoginUrl())) - . '")', - 'sort_order' => 15, - ]; + $data = $this->dataProvider->getData($customerId); } return $data; } - - /** - * Get Login as Customer login url. - * - * @return string - */ - public function getLoginUrl(): string - { - return $this->getUrl('loginascustomer/login/login', ['customer_id' => $this->getCustomerId()]); - } } diff --git a/app/code/Magento/LoginAsCustomerAdminUi/etc/adminhtml/di.xml b/app/code/Magento/LoginAsCustomerAdminUi/etc/adminhtml/di.xml index dabab45205527..b73a1d856c888 100644 --- a/app/code/Magento/LoginAsCustomerAdminUi/etc/adminhtml/di.xml +++ b/app/code/Magento/LoginAsCustomerAdminUi/etc/adminhtml/di.xml @@ -6,7 +6,17 @@ */ --> - + + + + Magento\LoginAsCustomerAdminUi\Ui\Customer\Component\Control\LoginAsCustomerButton\DataProvider + + + + + Magento\LoginAsCustomerAdminUi\Plugin\Button\ToolbarPlugin\DataProvider + + diff --git a/app/code/Magento/LoginAsCustomerAdminUi/etc/di.xml b/app/code/Magento/LoginAsCustomerAdminUi/etc/di.xml new file mode 100644 index 0000000000000..8ba8c5c6ead43 --- /dev/null +++ b/app/code/Magento/LoginAsCustomerAdminUi/etc/di.xml @@ -0,0 +1,31 @@ + + + + + + + + Login as Customer + login login-button + 15 + + + + + + + + Login as Customer + reset + + + + diff --git a/app/code/Magento/LoginAsCustomerApi/Api/Data/IsLoginAsCustomerEnabledForCustomerResultInterface.php b/app/code/Magento/LoginAsCustomerApi/Api/Data/IsLoginAsCustomerEnabledForCustomerResultInterface.php new file mode 100644 index 0000000000000..4f517fd7f315f --- /dev/null +++ b/app/code/Magento/LoginAsCustomerApi/Api/Data/IsLoginAsCustomerEnabledForCustomerResultInterface.php @@ -0,0 +1,37 @@ + Date: Mon, 6 Jul 2020 13:16:45 +0300 Subject: [PATCH 07/10] magento/magento2-login-as-customer#190: No order comments are created when admin is logged in as customer and place order with Multiple Addresses. --- .../Magento/LoginAsCustomerSales/etc/frontend/di.xml | 12 ++++++++++++ .../LoginAsCustomerSales/etc/webapi_rest/di.xml | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/LoginAsCustomerSales/etc/frontend/di.xml diff --git a/app/code/Magento/LoginAsCustomerSales/etc/frontend/di.xml b/app/code/Magento/LoginAsCustomerSales/etc/frontend/di.xml new file mode 100644 index 0000000000000..1a010fcdead85 --- /dev/null +++ b/app/code/Magento/LoginAsCustomerSales/etc/frontend/di.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/app/code/Magento/LoginAsCustomerSales/etc/webapi_rest/di.xml b/app/code/Magento/LoginAsCustomerSales/etc/webapi_rest/di.xml index 1a010fcdead85..6dda349f1e60d 100644 --- a/app/code/Magento/LoginAsCustomerSales/etc/webapi_rest/di.xml +++ b/app/code/Magento/LoginAsCustomerSales/etc/webapi_rest/di.xml @@ -7,6 +7,6 @@ --> - + From 289d609911cd607f1cf698747f5ecc9c0dec134c Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Wed, 8 Jul 2020 15:13:06 +0300 Subject: [PATCH 08/10] magento/magento2-login-as-customer#186: [CE] Admin cannot login as customer in two different customers account --- .../Plugin/InvalidateExpiredSessionPlugin.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/InvalidateExpiredSessionPlugin.php b/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/InvalidateExpiredSessionPlugin.php index b68e871c5f955..37aad2cef8998 100644 --- a/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/InvalidateExpiredSessionPlugin.php +++ b/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/InvalidateExpiredSessionPlugin.php @@ -61,7 +61,9 @@ public function beforeExecute(ActionInterface $subject) $customerId = (int)$this->session->getCustomerId(); if ($adminId && $customerId) { if (!$this->isLoginAsCustomerSessionActive->execute($customerId, $adminId)) { - $this->session->destroy(); + $this->session->clearStorage(); + $this->session->expireSessionCookie(); + $this->session->regenerateId(); } } } From 201b67bec993a1faa359e31f7212b43980d5cc1e Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Tue, 4 Aug 2020 21:48:07 -0500 Subject: [PATCH 09/10] magento/magento2-login-as-customer#144: "Login as Customer" functionality should be enabled by default. --- app/code/Magento/LoginAsCustomer/composer.json | 1 + .../Controller/Adminhtml/Login/Login.php | 3 ++- .../Ui/Customer/Component/Button/DataProvider.php | 2 -- .../IsLoginAsCustomerEnabledForCustomerResultInterface.php | 2 -- .../Api/IsLoginAsCustomerEnabledForCustomerInterface.php | 2 -- .../CustomerData/LoginAsCustomerUi.php | 3 ++- .../Model/AuthenticateCustomerBySecret.php | 3 ++- .../LoginAsCustomerFrontendUi/ViewModel/Configuration.php | 3 ++- app/code/Magento/LoginAsCustomerPageCache/composer.json | 3 ++- app/code/Magento/LoginAsCustomerSales/composer.json | 3 ++- 10 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/LoginAsCustomer/composer.json b/app/code/Magento/LoginAsCustomer/composer.json index ec81374528e7b..e58ec90e8f8bb 100755 --- a/app/code/Magento/LoginAsCustomer/composer.json +++ b/app/code/Magento/LoginAsCustomer/composer.json @@ -4,6 +4,7 @@ "require": { "php": "~7.3.0||~7.4.0", "magento/framework": "*", + "magento/module-backend": "*", "magento/module-customer": "*", "magento/module-login-as-customer-api": "*" }, diff --git a/app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php b/app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php index 1c2f0cbaa197c..39a7055ed65bb 100644 --- a/app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php +++ b/app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php @@ -131,7 +131,8 @@ public function __construct( $this->saveAuthenticationData = $saveAuthenticationData; $this->deleteAuthenticationDataForUser = $deleteAuthenticationDataForUser; $this->url = $url; - $this->setLoggedAsCustomerCustomerId = $setLoggedAsCustomerCustomerId ?? ObjectManager::getInstance()->get(SetLoggedAsCustomerCustomerIdInterface::class); + $this->setLoggedAsCustomerCustomerId = $setLoggedAsCustomerCustomerId + ?? ObjectManager::getInstance()->get(SetLoggedAsCustomerCustomerIdInterface::class); $this->isLoginAsCustomerEnabled = $isLoginAsCustomerEnabled ?? ObjectManager::getInstance()->get(IsLoginAsCustomerEnabledForCustomerInterface::class); } diff --git a/app/code/Magento/LoginAsCustomerAdminUi/Ui/Customer/Component/Button/DataProvider.php b/app/code/Magento/LoginAsCustomerAdminUi/Ui/Customer/Component/Button/DataProvider.php index 19db8c67f945e..24a70fc429467 100644 --- a/app/code/Magento/LoginAsCustomerAdminUi/Ui/Customer/Component/Button/DataProvider.php +++ b/app/code/Magento/LoginAsCustomerAdminUi/Ui/Customer/Component/Button/DataProvider.php @@ -14,8 +14,6 @@ * Get data for Login as Customer button. * * Use this class as a base for virtual types declaration. - * - * @api */ class DataProvider { diff --git a/app/code/Magento/LoginAsCustomerApi/Api/Data/IsLoginAsCustomerEnabledForCustomerResultInterface.php b/app/code/Magento/LoginAsCustomerApi/Api/Data/IsLoginAsCustomerEnabledForCustomerResultInterface.php index 4f517fd7f315f..b7d3a616176ef 100644 --- a/app/code/Magento/LoginAsCustomerApi/Api/Data/IsLoginAsCustomerEnabledForCustomerResultInterface.php +++ b/app/code/Magento/LoginAsCustomerApi/Api/Data/IsLoginAsCustomerEnabledForCustomerResultInterface.php @@ -9,8 +9,6 @@ /** * IsLoginAsCustomerEnabledForCustomerInterface results. - * - * @api */ interface IsLoginAsCustomerEnabledForCustomerResultInterface { diff --git a/app/code/Magento/LoginAsCustomerApi/Api/IsLoginAsCustomerEnabledForCustomerInterface.php b/app/code/Magento/LoginAsCustomerApi/Api/IsLoginAsCustomerEnabledForCustomerInterface.php index 7742bc23e421b..a5355fd4566d5 100644 --- a/app/code/Magento/LoginAsCustomerApi/Api/IsLoginAsCustomerEnabledForCustomerInterface.php +++ b/app/code/Magento/LoginAsCustomerApi/Api/IsLoginAsCustomerEnabledForCustomerInterface.php @@ -11,8 +11,6 @@ /** * Check if Login as Customer functionality is enabled for Customer. - * - * @api */ interface IsLoginAsCustomerEnabledForCustomerInterface { diff --git a/app/code/Magento/LoginAsCustomerFrontendUi/CustomerData/LoginAsCustomerUi.php b/app/code/Magento/LoginAsCustomerFrontendUi/CustomerData/LoginAsCustomerUi.php index 78ac010c965e3..140f31e3467f1 100644 --- a/app/code/Magento/LoginAsCustomerFrontendUi/CustomerData/LoginAsCustomerUi.php +++ b/app/code/Magento/LoginAsCustomerFrontendUi/CustomerData/LoginAsCustomerUi.php @@ -48,7 +48,8 @@ public function __construct( ) { $this->customerSession = $customerSession; $this->storeManager = $storeManager; - $this->getLoggedAsCustomerAdminId = $getLoggedAsCustomerAdminId ?? ObjectManager::getInstance()->get(GetLoggedAsCustomerAdminIdInterface::class); + $this->getLoggedAsCustomerAdminId = $getLoggedAsCustomerAdminId + ?? ObjectManager::getInstance()->get(GetLoggedAsCustomerAdminIdInterface::class); } /** diff --git a/app/code/Magento/LoginAsCustomerFrontendUi/Model/AuthenticateCustomerBySecret.php b/app/code/Magento/LoginAsCustomerFrontendUi/Model/AuthenticateCustomerBySecret.php index 2903016c36ddf..0604d2546ef79 100644 --- a/app/code/Magento/LoginAsCustomerFrontendUi/Model/AuthenticateCustomerBySecret.php +++ b/app/code/Magento/LoginAsCustomerFrontendUi/Model/AuthenticateCustomerBySecret.php @@ -48,7 +48,8 @@ public function __construct( ) { $this->getAuthenticationDataBySecret = $getAuthenticationDataBySecret; $this->customerSession = $customerSession; - $this->setLoggedAsCustomerAdminId = $setLoggedAsCustomerAdminId ?? ObjectManager::getInstance()->get(SetLoggedAsCustomerAdminIdInterface::class); + $this->setLoggedAsCustomerAdminId = $setLoggedAsCustomerAdminId + ?? ObjectManager::getInstance()->get(SetLoggedAsCustomerAdminIdInterface::class); } /** diff --git a/app/code/Magento/LoginAsCustomerFrontendUi/ViewModel/Configuration.php b/app/code/Magento/LoginAsCustomerFrontendUi/ViewModel/Configuration.php index e7a5cd146410e..357ede238585b 100644 --- a/app/code/Magento/LoginAsCustomerFrontendUi/ViewModel/Configuration.php +++ b/app/code/Magento/LoginAsCustomerFrontendUi/ViewModel/Configuration.php @@ -45,7 +45,8 @@ public function __construct( ) { $this->config = $config; $this->httpContext = $httpContext; - $this->getLoggedAsCustomerAdminId = $getLoggedAsCustomerAdminId ?? ObjectManager::getInstance()->get(GetLoggedAsCustomerAdminIdInterface::class); + $this->getLoggedAsCustomerAdminId = $getLoggedAsCustomerAdminId + ?? ObjectManager::getInstance()->get(GetLoggedAsCustomerAdminIdInterface::class); } /** diff --git a/app/code/Magento/LoginAsCustomerPageCache/composer.json b/app/code/Magento/LoginAsCustomerPageCache/composer.json index 195a08fc19d83..410808f9e79f6 100644 --- a/app/code/Magento/LoginAsCustomerPageCache/composer.json +++ b/app/code/Magento/LoginAsCustomerPageCache/composer.json @@ -5,7 +5,8 @@ "php": "~7.3.0||~7.4.0", "magento/framework": "*", "magento/module-customer": "*", - "magento/module-store": "*" + "magento/module-store": "*", + "magento/module-login-as-customer-api": "*" }, "suggest": { "magento/module-page-cache": "*" diff --git a/app/code/Magento/LoginAsCustomerSales/composer.json b/app/code/Magento/LoginAsCustomerSales/composer.json index 3965e8acf87d8..e93b40e0440c8 100644 --- a/app/code/Magento/LoginAsCustomerSales/composer.json +++ b/app/code/Magento/LoginAsCustomerSales/composer.json @@ -6,7 +6,8 @@ "magento/framework": "*", "magento/module-backend": "*", "magento/module-customer": "*", - "magento/module-user": "*" + "magento/module-user": "*", + "magento/module-login-as-customer-api": "*" }, "suggest": { "magento/module-sales": "*" From 00f5d468c2fd86b1c6ccbb8f79cfa75b009d5976 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Tue, 4 Aug 2020 22:33:25 -0500 Subject: [PATCH 10/10] magento/magento2-login-as-customer#144: "Login as Customer" functionality should be enabled by default. --- .../Model/AuthenticateCustomerBySecret.php | 2 +- .../LoginAsCustomerAdminUi/Plugin/Button/ToolbarPlugin.php | 5 ++--- .../Magento/LoginAsCustomerFrontendUi/etc/frontend/di.xml | 1 - app/code/Magento/LoginAsCustomerPageCache/composer.json | 1 - app/code/Magento/LoginAsCustomerSales/composer.json | 1 - 5 files changed, 3 insertions(+), 7 deletions(-) rename app/code/Magento/{LoginAsCustomerFrontendUi => LoginAsCustomer}/Model/AuthenticateCustomerBySecret.php (97%) diff --git a/app/code/Magento/LoginAsCustomerFrontendUi/Model/AuthenticateCustomerBySecret.php b/app/code/Magento/LoginAsCustomer/Model/AuthenticateCustomerBySecret.php similarity index 97% rename from app/code/Magento/LoginAsCustomerFrontendUi/Model/AuthenticateCustomerBySecret.php rename to app/code/Magento/LoginAsCustomer/Model/AuthenticateCustomerBySecret.php index 0604d2546ef79..808b01bac58aa 100644 --- a/app/code/Magento/LoginAsCustomerFrontendUi/Model/AuthenticateCustomerBySecret.php +++ b/app/code/Magento/LoginAsCustomer/Model/AuthenticateCustomerBySecret.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magento\LoginAsCustomerFrontendUi\Model; +namespace Magento\LoginAsCustomer\Model; use Magento\Customer\Model\Session; use Magento\Framework\App\ObjectManager; diff --git a/app/code/Magento/LoginAsCustomerAdminUi/Plugin/Button/ToolbarPlugin.php b/app/code/Magento/LoginAsCustomerAdminUi/Plugin/Button/ToolbarPlugin.php index 3516a181b5dde..c67b0d9dd5273 100644 --- a/app/code/Magento/LoginAsCustomerAdminUi/Plugin/Button/ToolbarPlugin.php +++ b/app/code/Magento/LoginAsCustomerAdminUi/Plugin/Button/ToolbarPlugin.php @@ -8,7 +8,6 @@ namespace Magento\LoginAsCustomerAdminUi\Plugin\Button; use Magento\Backend\Block\Widget\Button\ButtonList; -use Magento\Backend\Block\Widget\Button\Toolbar; use Magento\Framework\AuthorizationInterface; use Magento\Framework\Escaper; use Magento\Framework\View\Element\AbstractBlock; @@ -62,13 +61,13 @@ public function __construct( /** * Add Login as Customer button. * - * @param \Magento\Backend\Block\Widget\Button\Toolbar $subject + * @param \Magento\Backend\Block\Widget\Button\ToolbarInterface $subject * @param \Magento\Framework\View\Element\AbstractBlock $context * @param \Magento\Backend\Block\Widget\Button\ButtonList $buttonList * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforePushButtons( - Toolbar $subject, + \Magento\Backend\Block\Widget\Button\ToolbarInterface $subject, AbstractBlock $context, ButtonList $buttonList ): void { diff --git a/app/code/Magento/LoginAsCustomerFrontendUi/etc/frontend/di.xml b/app/code/Magento/LoginAsCustomerFrontendUi/etc/frontend/di.xml index e42d33383ac42..bff511b6bb6e6 100644 --- a/app/code/Magento/LoginAsCustomerFrontendUi/etc/frontend/di.xml +++ b/app/code/Magento/LoginAsCustomerFrontendUi/etc/frontend/di.xml @@ -6,7 +6,6 @@ */ --> - diff --git a/app/code/Magento/LoginAsCustomerPageCache/composer.json b/app/code/Magento/LoginAsCustomerPageCache/composer.json index 410808f9e79f6..84d7f2e2a6730 100644 --- a/app/code/Magento/LoginAsCustomerPageCache/composer.json +++ b/app/code/Magento/LoginAsCustomerPageCache/composer.json @@ -4,7 +4,6 @@ "require": { "php": "~7.3.0||~7.4.0", "magento/framework": "*", - "magento/module-customer": "*", "magento/module-store": "*", "magento/module-login-as-customer-api": "*" }, diff --git a/app/code/Magento/LoginAsCustomerSales/composer.json b/app/code/Magento/LoginAsCustomerSales/composer.json index e93b40e0440c8..3891504e54092 100644 --- a/app/code/Magento/LoginAsCustomerSales/composer.json +++ b/app/code/Magento/LoginAsCustomerSales/composer.json @@ -5,7 +5,6 @@ "php": "~7.3.0||~7.4.0", "magento/framework": "*", "magento/module-backend": "*", - "magento/module-customer": "*", "magento/module-user": "*", "magento/module-login-as-customer-api": "*" },