Skip to content

Commit 2c8b742

Browse files
authored
Merge pull request #123 from ihorvansach/issue-110
Added spinner/loader while Admin is logging in as Customer
2 parents dc7ba27 + 6746254 commit 2c8b742

File tree

10 files changed

+55
-71
lines changed

10 files changed

+55
-71
lines changed

app/code/Magento/LoginAsCustomerPageCache/etc/adminhtml/system.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<field id="disable_page_cache" translate="label comment" type="select" sortOrder="20" showInDefault="1" canRestore="1">
1313
<label>Disable Page Cache For Admin User</label>
1414
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
15-
<comment><![CDATA[If set to "Yes", when login as customer Page Cache will be disabled.]]></comment>
15+
<comment><![CDATA[If set to "Yes", page caching is disabled when the Admin user is logged in as a customer.]]></comment>
1616
</field>
1717
</group>
1818
</section>

app/code/Magento/LoginAsCustomerUi/Block/Adminhtml/ConfirmationPopup.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,17 @@ public function getJsLayout()
7979

8080
return $this->json->serialize($layout);
8181
}
82+
83+
/**
84+
* Render block HTML
85+
*
86+
* @return string
87+
*/
88+
protected function _toHtml()
89+
{
90+
if (!$this->config->isEnabled()) {
91+
return '';
92+
}
93+
return parent::_toHtml();
94+
}
8295
}

app/code/Magento/LoginAsCustomerUi/Controller/Login/Index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ public function execute(): ResultInterface
116116
$this->messageManager->addSuccessMessage(
117117
__('You are logged in as customer: %1', $customer->getFirstname() . ' ' . $customer->getLastname())
118118
);
119-
$resultRedirect->setPath('*/*/proceed');
119+
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
120+
$resultPage->getConfig()->getTitle()->set(__('You are logged in'));
121+
return $this->resultFactory->create(ResultFactory::TYPE_PAGE);
120122

121123
} catch (LocalizedException $e) {
122124
$this->messageManager->addErrorMessage($e->getMessage());

app/code/Magento/LoginAsCustomerUi/Controller/Login/Proceed.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

app/code/Magento/LoginAsCustomerUi/Model/Config/Source/StoreViewLogin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function toOptionArray(): array
2929
{
3030
return [
3131
['value' => self::AUTODETECT, 'label' => __('Auto-Detection (default)')],
32-
['value' => self::MANUAL, 'label' => __('Manual Choose')],
32+
['value' => self::MANUAL, 'label' => __('Manual Selection')],
3333
];
3434
}
3535
}

app/code/Magento/LoginAsCustomerUi/Plugin/Button/ToolbarPlugin.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\View\Element\AbstractBlock;
1313
use Magento\Framework\Escaper;
1414
use Magento\Framework\AuthorizationInterface;
15+
use Magento\LoginAsCustomerApi\Api\ConfigInterface;
1516

1617
/**
1718
* Plugin for \Magento\Backend\Block\Widget\Button\Toolbar.
@@ -28,16 +29,24 @@ class ToolbarPlugin
2829
*/
2930
private $escaper;
3031

32+
/**
33+
* @var ConfigInterface
34+
*/
35+
private $config;
36+
3137
/**
3238
* ToolbarPlugin constructor.
3339
* @param AuthorizationInterface $authorization
40+
* @param ConfigInterface $config
3441
* @param Escaper $escaper
3542
*/
3643
public function __construct(
3744
AuthorizationInterface $authorization,
45+
ConfigInterface $config,
3846
Escaper $escaper
3947
) {
4048
$this->authorization = $authorization;
49+
$this->config = $config;
4150
$this->escaper = $escaper;
4251
}
4352

@@ -67,7 +76,10 @@ public function beforePushButtons(
6776
$order = $context->getCreditmemo()->getOrder();
6877
}
6978
if ($order) {
70-
if ($this->isAllowed()) {
79+
80+
$isAllowed = $this->authorization->isAllowed('Magento_LoginAsCustomer::login_button');
81+
$isEnabled = $this->config->isEnabled();
82+
if ($isAllowed && $isEnabled) {
7183
if (!empty($order['customer_id'])) {
7284
$buttonUrl = $context->getUrl('loginascustomer/login/login', [
7385
'customer_id' => $order['customer_id']
@@ -87,14 +99,4 @@ public function beforePushButtons(
8799
}
88100
}
89101
}
90-
91-
/**
92-
* Check is allowed access
93-
*
94-
* @return bool
95-
*/
96-
private function isAllowed(): bool
97-
{
98-
return (bool)$this->authorization->isAllowed('Magento_LoginAsCustomer::login_button');
99-
}
100102
}

app/code/Magento/LoginAsCustomerUi/Ui/Customer/Component/Control/LoginAsCustomerButton.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,28 @@
88
namespace Magento\LoginAsCustomerUi\Ui\Customer\Component\Control;
99

1010
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
11+
use Magento\Framework\AuthorizationInterface;
1112
use Magento\Framework\Escaper;
1213
use Magento\Framework\Registry;
1314
use Magento\Backend\Block\Widget\Context;
1415
use Magento\Customer\Block\Adminhtml\Edit\GenericButton;
16+
use Magento\LoginAsCustomerApi\Api\ConfigInterface;
1517

1618
/**
1719
* Login As Customer button UI component.
1820
*/
1921
class LoginAsCustomerButton extends GenericButton implements ButtonProviderInterface
2022
{
2123
/**
22-
* @var \Magento\Framework\AuthorizationInterface
24+
* @var AuthorizationInterface
2325
*/
2426
private $authorization;
2527

28+
/**
29+
* @var ConfigInterface
30+
*/
31+
private $config;
32+
2633
/**
2734
* Escaper
2835
*
@@ -33,13 +40,16 @@ class LoginAsCustomerButton extends GenericButton implements ButtonProviderInter
3340
/**
3441
* @param Context $context
3542
* @param Registry $registry
43+
* @param ConfigInterface $config
3644
*/
3745
public function __construct(
3846
Context $context,
39-
Registry $registry
47+
Registry $registry,
48+
ConfigInterface $config
4049
) {
4150
parent::__construct($context, $registry);
4251
$this->authorization = $context->getAuthorization();
52+
$this->config = $config;
4353
$this->escaper = $context->getEscaper();
4454
}
4555

@@ -50,8 +60,9 @@ public function getButtonData(): array
5060
{
5161
$customerId = $this->getCustomerId();
5262
$data = [];
53-
$canModify = $customerId && $this->authorization->isAllowed('Magento_LoginAsCustomer::login_button');
54-
if ($canModify) {
63+
$isAllowed = $customerId && $this->authorization->isAllowed('Magento_LoginAsCustomer::login_button');
64+
$isEnabled = $this->config->isEnabled();
65+
if ($isAllowed && $isEnabled) {
5566
$data = [
5667
'label' => __('Login As Customer'),
5768
'class' => 'login login-button',

app/code/Magento/LoginAsCustomerUi/etc/adminhtml/system.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
99
<system>
10-
<section id="login_as_customer" translate="label" type="text" sortOrder="1" showInDefault="1" >
10+
<section id="login_as_customer" translate="label" type="text" sortOrder="1" showInDefault="1">
1111
<class>separator-top</class>
12-
<label>Login As Customer</label>
12+
<label>Login as Customer</label>
1313
<tab>customer</tab>
1414
<resource>Magento_LoginAsCustomer::config_section</resource>
1515
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" canRestore="1">
16-
<label>Login As Customer Information</label>
16+
<label>Login as Customer Settings</label>
1717
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" canRestore="1">
1818
<label>Enable Extension</label>
1919
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
2020
</field>
2121
<field id="store_view_manual_choice_enabled" translate="label comment" type="select" sortOrder="40" showInDefault="1" canRestore="1">
22-
<label>Store View To Login In</label>
22+
<label>Store View To Login To</label>
2323
<source_model>Magento\LoginAsCustomerUi\Model\Config\Source\StoreViewLogin</source_model>
2424
<comment><![CDATA[
25-
Use "Manual Choose" option on multi-website Magento setup with enabled global Share Customer Accounts.
26-
If set to "Manual Choose" then after click on "Login As Customer" admin will need to choose from a select box a store view to login in.
25+
Use the "Manual Selection" option on a multi-website setup that has "Share Customer Accounts" enabled globally.
26+
If set to "Manual Selection", the "Login as Customer" admin can select a store view after logging in.
2727
]]></comment>
2828
</field>
2929
</group>

app/code/Magento/LoginAsCustomerUi/view/frontend/web/js/login.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
*/
55

66
define([
7+
'jquery',
78
'Magento_Customer/js/customer-data',
89
'Magento_Customer/js/section-config'
9-
], function (customerData, sectionConfig) {
10+
], function ($, customerData, sectionConfig) {
1011

1112
'use strict';
1213

1314
return function (config) {
15+
$('body').trigger('processStart');
1416
customerData.reload(sectionConfig.getSectionNames()).done(function () {
1517
window.location.href = config.redirectUrl;
1618
});

0 commit comments

Comments
 (0)