Skip to content

Commit 59d3dfa

Browse files
committed
Confirmation pop-up window for Login as Customer
1 parent 27c3c83 commit 59d3dfa

File tree

18 files changed

+355
-193
lines changed

18 files changed

+355
-193
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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\LoginAsCustomerUi\Block\Adminhtml;
9+
10+
use Magento\Framework\Serialize\Serializer\Json;
11+
use Magento\Store\Ui\Component\Listing\Column\Store\Options as StoreOptions;
12+
use Magento\Backend\Block\Template;
13+
use Magento\LoginAsCustomerApi\Api\ConfigInterface;
14+
15+
/**
16+
* Admin blog post
17+
*/
18+
class ConfirmationPopup extends Template
19+
{
20+
21+
/**
22+
* Store Options
23+
*
24+
* @var StoreOptions
25+
*/
26+
private $storeOptions;
27+
28+
/**
29+
* Config
30+
*
31+
* @var ConfigInterface
32+
*/
33+
private $config;
34+
35+
/**
36+
* Json Serializer
37+
*
38+
* @var Json
39+
*/
40+
private $json;
41+
42+
43+
/**
44+
* ConfirmationPopup constructor.
45+
* @param Template\Context $context
46+
* @param SystemStore $systemStore
47+
* @param StoreOptions $toreOptions
48+
* @param ConfigInterface $config
49+
* @param Json $json
50+
* @param array $data
51+
*/
52+
public function __construct(
53+
Template\Context $context,
54+
StoreOptions $toreOptions,
55+
ConfigInterface $config,
56+
Json $json,
57+
array $data = []
58+
) {
59+
parent::__construct($context, $data);
60+
$this->storeOptions = $toreOptions;
61+
$this->config = $config;
62+
$this->json = $json;
63+
}
64+
65+
/**
66+
* @return string
67+
*/
68+
public function getJsLayout()
69+
{
70+
$layout = $this->json->unserialize(parent::getJsLayout());
71+
$showStoreViewOptions = $this->config->isStoreManualChoiceEnabled();
72+
73+
$layout['components']['lac-confirmation-popup']['title'] = $showStoreViewOptions
74+
? __('Login as Customer: Select Store View')
75+
: __('You are about to Login as Customer');
76+
$layout['components']['lac-confirmation-popup']['content'] = __('Actions taken while in "Login as Customer" will affect actual customer data.');
77+
78+
$layout['components']['lac-confirmation-popup']['showStoreViewOptions'] = $showStoreViewOptions;
79+
$layout['components']['lac-confirmation-popup']['storeViewOptions'] = $showStoreViewOptions
80+
? $this->storeOptions->toOptionArray()
81+
: [];
82+
83+
return $this->json->serialize($layout);
84+
}
85+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ public function execute(): ResultInterface
135135
return $resultRedirect->setPath('customer/index/index');
136136
}
137137

138-
$storeId = $this->_request->getParam('store_id');
138+
$storeId = (int)$this->_request->getParam('store_id');
139139
if (empty($storeId) && $this->config->isStoreManualChoiceEnabled()) {
140140
$this->messageManager->addNoticeMessage(__('Please select a Store View to login in.'));
141-
return $resultRedirect->setPath('loginascustomer/login/manual', ['customer_id' => $customerId]);
141+
return $resultRedirect->setPath('customer/index/edit', ['id' => $customerId]);
142142
}
143143

144144
$adminUser = $this->authSession->getUser();

app/code/Magento/LoginAsCustomerUi/Controller/Adminhtml/Login/Manual.php

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

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,35 @@
1010
use Magento\Backend\Block\Widget\Button\ButtonList;
1111
use Magento\Backend\Block\Widget\Button\Toolbar;
1212
use Magento\Framework\View\Element\AbstractBlock;
13+
use Magento\Framework\Escaper;
14+
use Magento\Framework\AuthorizationInterface;
1315

1416
/**
1517
* Plugin for \Magento\Backend\Block\Widget\Button\Toolbar.
1618
*/
1719
class ToolbarPlugin
1820
{
1921
/**
20-
* @var \Magento\Framework\AuthorizationInterface
22+
* @var AuthorizationInterface
2123
*/
2224
private $authorization;
2325

2426
/**
25-
* @var \Magento\Framework\UrlInterface
27+
* @var Escaper
2628
*/
27-
private $url;
29+
private $escaper;
2830

2931
/**
3032
* ToolbarPlugin constructor.
31-
* @param \Magento\Framework\AuthorizationInterface $authorization
32-
* @param \Magento\Framework\UrlInterface $url
33+
* @param AuthorizationInterface $authorization
34+
* @param Escaper $escaper
3335
*/
3436
public function __construct(
35-
\Magento\Framework\AuthorizationInterface $authorization,
36-
\Magento\Framework\UrlInterface $url
37+
AuthorizationInterface $authorization,
38+
Escaper $escaper
3739
) {
3840
$this->authorization = $authorization;
39-
$this->url = $url;
41+
$this->escaper = $escaper;
4042
}
4143

4244
/**
@@ -74,7 +76,9 @@ public function beforePushButtons(
7476
'guest_to_customer',
7577
[
7678
'label' => __('Login As Customer'),
77-
'onclick' => 'window.open(\'' . $buttonUrl . '\')',
79+
'onclick' => 'window.lacConfirmationPopup("'
80+
. $this->escaper->escapeHtml($this->escaper->escapeJs($buttonUrl))
81+
. '")',
7882
'class' => 'reset'
7983
],
8084
-1

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77

88
namespace Magento\LoginAsCustomerUi\Ui\Customer\Component\Control;
99

10-
use Magento\Customer\Block\Adminhtml\Edit\GenericButton;
1110
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
11+
use Magento\Framework\Escaper;
12+
use Magento\Framework\Registry;
13+
use Magento\Backend\Block\Widget\Context;
14+
use Magento\Customer\Block\Adminhtml\Edit\GenericButton;
1215

1316
/**
1417
* Login As Customer button UI component.
@@ -21,15 +24,23 @@ class LoginAsCustomerButton extends GenericButton implements ButtonProviderInter
2124
private $authorization;
2225

2326
/**
24-
* @param \Magento\Backend\Block\Widget\Context $context
25-
* @param \Magento\Framework\Registry $registry
27+
* Escaper
28+
*
29+
* @var Escaper
30+
*/
31+
private $escaper;
32+
33+
/**
34+
* @param Context $context
35+
* @param Registry $registry
2636
*/
2737
public function __construct(
28-
\Magento\Backend\Block\Widget\Context $context,
29-
\Magento\Framework\Registry $registry
38+
Context $context,
39+
Registry $registry
3040
) {
3141
parent::__construct($context, $registry);
3242
$this->authorization = $context->getAuthorization();
43+
$this->escaper = $context->getEscaper();
3344
}
3445

3546
/**
@@ -44,8 +55,9 @@ public function getButtonData(): array
4455
$data = [
4556
'label' => __('Login As Customer'),
4657
'class' => 'login login-button',
47-
'on_click' => 'window.open( \'' . $this->getLoginUrl() .
48-
'\')',
58+
'on_click' => 'window.lacConfirmationPopup("'
59+
. $this->escaper->escapeHtml($this->escaper->escapeJs($this->getLoginUrl()))
60+
. '")',
4961
'sort_order' => 70,
5062
];
5163
}

app/code/Magento/LoginAsCustomerUi/Ui/Store/DataProvider/Form/StoreDataProvider.php

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
9+
<update handle="loginascustomer_confirmation_popup" />
10+
</layout>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
9+
<update handle="loginascustomer_confirmation_popup" />
10+
</layout>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
9+
<referenceContainer name="content">
10+
<block class="Magento\LoginAsCustomerUi\Block\Adminhtml\ConfirmationPopup" name="lac.confirmation.popup" template="Magento_LoginAsCustomerUi::confirmation-popup.phtml">
11+
<arguments>
12+
<argument name="jsLayout" xsi:type="array">
13+
<item name="components" xsi:type="array">
14+
<item name="lac-confirmation-popup" xsi:type="array">
15+
<item name="component" xsi:type="string">Magento_LoginAsCustomerUi/js/confirmation-popup</item>
16+
</item>
17+
</item>
18+
</argument>
19+
</arguments>
20+
</block>
21+
</referenceContainer>
22+
</layout>

app/code/Magento/LoginAsCustomerUi/view/adminhtml/layout/loginascustomer_login_manual.xml

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

0 commit comments

Comments
 (0)