From 14dfbc089a5670f8e4ee4d87ef8ef3b9160bc60b Mon Sep 17 00:00:00 2001 From: Ihor Vansach Date: Wed, 29 Apr 2020 13:33:14 +0300 Subject: [PATCH 1/3] [fixed] Login As Customer functionality is available when Login As Customer->Enable Extension=No --- .../Block/Adminhtml/ConfirmationPopup.php | 13 ++++++++++ .../Plugin/Button/ToolbarPlugin.php | 24 ++++++++++--------- .../Control/LoginAsCustomerButton.php | 19 +++++++++++---- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/app/code/Magento/LoginAsCustomerUi/Block/Adminhtml/ConfirmationPopup.php b/app/code/Magento/LoginAsCustomerUi/Block/Adminhtml/ConfirmationPopup.php index afea338fce780..5f8310df49622 100644 --- a/app/code/Magento/LoginAsCustomerUi/Block/Adminhtml/ConfirmationPopup.php +++ b/app/code/Magento/LoginAsCustomerUi/Block/Adminhtml/ConfirmationPopup.php @@ -79,4 +79,17 @@ public function getJsLayout() return $this->json->serialize($layout); } + + /** + * Render block HTML + * + * @return string + */ + protected function _toHtml() + { + if (!$this->config->isEnabled()) { + return ''; + } + return parent::_toHtml(); + } } diff --git a/app/code/Magento/LoginAsCustomerUi/Plugin/Button/ToolbarPlugin.php b/app/code/Magento/LoginAsCustomerUi/Plugin/Button/ToolbarPlugin.php index 8563646baf9bf..ec2c4dd5dcb65 100644 --- a/app/code/Magento/LoginAsCustomerUi/Plugin/Button/ToolbarPlugin.php +++ b/app/code/Magento/LoginAsCustomerUi/Plugin/Button/ToolbarPlugin.php @@ -12,6 +12,7 @@ use Magento\Framework\View\Element\AbstractBlock; use Magento\Framework\Escaper; use Magento\Framework\AuthorizationInterface; +use Magento\LoginAsCustomerApi\Api\ConfigInterface; /** * Plugin for \Magento\Backend\Block\Widget\Button\Toolbar. @@ -28,16 +29,24 @@ class ToolbarPlugin */ private $escaper; + /** + * @var ConfigInterface + */ + private $config; + /** * ToolbarPlugin constructor. * @param AuthorizationInterface $authorization + * @param ConfigInterface $config * @param Escaper $escaper */ public function __construct( AuthorizationInterface $authorization, + ConfigInterface $config, Escaper $escaper ) { $this->authorization = $authorization; + $this->config = $config; $this->escaper = $escaper; } @@ -67,7 +76,10 @@ public function beforePushButtons( $order = $context->getCreditmemo()->getOrder(); } if ($order) { - if ($this->isAllowed()) { + + $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'] @@ -87,14 +99,4 @@ public function beforePushButtons( } } } - - /** - * Check is allowed access - * - * @return bool - */ - private function isAllowed(): bool - { - return (bool)$this->authorization->isAllowed('Magento_LoginAsCustomer::login_button'); - } } diff --git a/app/code/Magento/LoginAsCustomerUi/Ui/Customer/Component/Control/LoginAsCustomerButton.php b/app/code/Magento/LoginAsCustomerUi/Ui/Customer/Component/Control/LoginAsCustomerButton.php index 794f42cb63eef..88add39eb1efb 100644 --- a/app/code/Magento/LoginAsCustomerUi/Ui/Customer/Component/Control/LoginAsCustomerButton.php +++ b/app/code/Magento/LoginAsCustomerUi/Ui/Customer/Component/Control/LoginAsCustomerButton.php @@ -8,10 +8,12 @@ namespace Magento\LoginAsCustomerUi\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\LoginAsCustomerApi\Api\ConfigInterface; /** * Login As Customer button UI component. @@ -19,10 +21,15 @@ class LoginAsCustomerButton extends GenericButton implements ButtonProviderInterface { /** - * @var \Magento\Framework\AuthorizationInterface + * @var AuthorizationInterface */ private $authorization; + /** + * @var ConfigInterface + */ + private $config; + /** * Escaper * @@ -33,13 +40,16 @@ class LoginAsCustomerButton extends GenericButton implements ButtonProviderInter /** * @param Context $context * @param Registry $registry + * @param ConfigInterface $config */ public function __construct( Context $context, - Registry $registry + Registry $registry, + ConfigInterface $config ) { parent::__construct($context, $registry); $this->authorization = $context->getAuthorization(); + $this->config = $config; $this->escaper = $context->getEscaper(); } @@ -50,8 +60,9 @@ public function getButtonData(): array { $customerId = $this->getCustomerId(); $data = []; - $canModify = $customerId && $this->authorization->isAllowed('Magento_LoginAsCustomer::login_button'); - if ($canModify) { + $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', From 14ee4673d1dcaa5afb6777b6229ef2844976023c Mon Sep 17 00:00:00 2001 From: Ihor Vansach Date: Wed, 29 Apr 2020 14:02:51 +0300 Subject: [PATCH 2/3] Changed texts and labels in LoginAsCustomer [issue96] --- .../LoginAsCustomerPageCache/etc/adminhtml/system.xml | 2 +- .../Model/Config/Source/StoreViewLogin.php | 2 +- .../Magento/LoginAsCustomerUi/etc/adminhtml/system.xml | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/LoginAsCustomerPageCache/etc/adminhtml/system.xml b/app/code/Magento/LoginAsCustomerPageCache/etc/adminhtml/system.xml index 7fc1826932ce4..a7e56a43fab19 100644 --- a/app/code/Magento/LoginAsCustomerPageCache/etc/adminhtml/system.xml +++ b/app/code/Magento/LoginAsCustomerPageCache/etc/adminhtml/system.xml @@ -12,7 +12,7 @@ Magento\Config\Model\Config\Source\Yesno - + diff --git a/app/code/Magento/LoginAsCustomerUi/Model/Config/Source/StoreViewLogin.php b/app/code/Magento/LoginAsCustomerUi/Model/Config/Source/StoreViewLogin.php index 3d1d627fd7b93..cf77f695287fd 100644 --- a/app/code/Magento/LoginAsCustomerUi/Model/Config/Source/StoreViewLogin.php +++ b/app/code/Magento/LoginAsCustomerUi/Model/Config/Source/StoreViewLogin.php @@ -29,7 +29,7 @@ public function toOptionArray(): array { return [ ['value' => self::AUTODETECT, 'label' => __('Auto-Detection (default)')], - ['value' => self::MANUAL, 'label' => __('Manual Choose')], + ['value' => self::MANUAL, 'label' => __('Manual Selection')], ]; } } diff --git a/app/code/Magento/LoginAsCustomerUi/etc/adminhtml/system.xml b/app/code/Magento/LoginAsCustomerUi/etc/adminhtml/system.xml index d0c5da375ecbe..caa6c6986b42a 100755 --- a/app/code/Magento/LoginAsCustomerUi/etc/adminhtml/system.xml +++ b/app/code/Magento/LoginAsCustomerUi/etc/adminhtml/system.xml @@ -9,21 +9,21 @@
separator-top - + customer Magento_LoginAsCustomer::config_section - + Magento\Config\Model\Config\Source\Yesno - + Magento\LoginAsCustomerUi\Model\Config\Source\StoreViewLogin From ab73754c87e7b1d3f546783a6c118af2aa12225a Mon Sep 17 00:00:00 2001 From: Ihor Vansach Date: Wed, 29 Apr 2020 14:28:19 +0300 Subject: [PATCH 3/3] Removed 1 redirect and added loader on storefront login page in LoginAsCustomer --- .../Controller/Login/Index.php | 4 +- .../Controller/Login/Proceed.php | 46 ------------------- ...ed.xml => loginascustomer_login_index.xml} | 0 .../view/frontend/web/js/login.js | 4 +- 4 files changed, 6 insertions(+), 48 deletions(-) delete mode 100755 app/code/Magento/LoginAsCustomerUi/Controller/Login/Proceed.php rename app/code/Magento/LoginAsCustomerUi/view/frontend/layout/{loginascustomer_login_proceed.xml => loginascustomer_login_index.xml} (100%) diff --git a/app/code/Magento/LoginAsCustomerUi/Controller/Login/Index.php b/app/code/Magento/LoginAsCustomerUi/Controller/Login/Index.php index 0532846cf2535..131031068edcc 100755 --- a/app/code/Magento/LoginAsCustomerUi/Controller/Login/Index.php +++ b/app/code/Magento/LoginAsCustomerUi/Controller/Login/Index.php @@ -127,7 +127,9 @@ public function execute(): ResultInterface $this->messageManager->addSuccessMessage( __('You are logged in as customer: %1', $customer->getFirstname() . ' ' . $customer->getLastname()) ); - $resultRedirect->setPath('*/*/proceed'); + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->getConfig()->getTitle()->set(__('You are logged in')); + return $this->resultFactory->create(ResultFactory::TYPE_PAGE); } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); diff --git a/app/code/Magento/LoginAsCustomerUi/Controller/Login/Proceed.php b/app/code/Magento/LoginAsCustomerUi/Controller/Login/Proceed.php deleted file mode 100755 index b722218bef705..0000000000000 --- a/app/code/Magento/LoginAsCustomerUi/Controller/Login/Proceed.php +++ /dev/null @@ -1,46 +0,0 @@ -resultFactory = $resultFactory; - } - - /** - * Proxy page - * - * @return ResultInterface - */ - public function execute(): ResultInterface - { - /** @var Page $resultPage */ - $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); - $resultPage->getConfig()->getTitle()->set(__('You are logged in')); - return $this->resultFactory->create(ResultFactory::TYPE_PAGE); - } -} diff --git a/app/code/Magento/LoginAsCustomerUi/view/frontend/layout/loginascustomer_login_proceed.xml b/app/code/Magento/LoginAsCustomerUi/view/frontend/layout/loginascustomer_login_index.xml similarity index 100% rename from app/code/Magento/LoginAsCustomerUi/view/frontend/layout/loginascustomer_login_proceed.xml rename to app/code/Magento/LoginAsCustomerUi/view/frontend/layout/loginascustomer_login_index.xml diff --git a/app/code/Magento/LoginAsCustomerUi/view/frontend/web/js/login.js b/app/code/Magento/LoginAsCustomerUi/view/frontend/web/js/login.js index 1e59c988015ec..ab325bc90cf00 100644 --- a/app/code/Magento/LoginAsCustomerUi/view/frontend/web/js/login.js +++ b/app/code/Magento/LoginAsCustomerUi/view/frontend/web/js/login.js @@ -4,13 +4,15 @@ */ define([ + 'jquery', 'Magento_Customer/js/customer-data', 'Magento_Customer/js/section-config' -], function (customerData, sectionConfig) { +], function ($, customerData, sectionConfig) { 'use strict'; return function (config) { + $('body').trigger('processStart'); customerData.reload(sectionConfig.getSectionNames()).done(function () { window.location.href = config.redirectUrl; });