Skip to content

Commit dc7ba27

Browse files
authored
Merge pull request #119 from ihorvansach/confirmation-popup-window-ui-v2
Confirmation pop-up window for "Login as Customer" (New Request)
2 parents 656d6a2 + e5f5c64 commit dc7ba27

File tree

18 files changed

+349
-193
lines changed

18 files changed

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

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

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

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

155155
$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.
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: 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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
/** @var \Magento\LoginAsCustomerUi\Block\Adminhtml\ConfirmationPopup $block */
7+
?>
8+
9+
<script type="text/x-magento-init">
10+
{
11+
"*": {
12+
"Magento_Ui/js/core/app": <?php /* @escapeNotVerified */ echo $block->getJsLayout();?>
13+
}
14+
}
15+
</script>

0 commit comments

Comments
 (0)