Skip to content

Commit

Permalink
Merge pull request #119 from ihorvansach/confirmation-popup-window-ui-v2
Browse files Browse the repository at this point in the history
Confirmation pop-up window for "Login as Customer" (New Request)
  • Loading branch information
naydav authored Apr 30, 2020
2 parents 656d6a2 + e5f5c64 commit dc7ba27
Show file tree
Hide file tree
Showing 18 changed files with 349 additions and 193 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\LoginAsCustomerUi\Block\Adminhtml;

use Magento\Framework\Serialize\Serializer\Json;
use Magento\Store\Ui\Component\Listing\Column\Store\Options as StoreOptions;
use Magento\Backend\Block\Template;
use Magento\LoginAsCustomerApi\Api\ConfigInterface;

/**
* Admin blog post
*/
class ConfirmationPopup extends Template
{
/**
* Store Options
*
* @var StoreOptions
*/
private $storeOptions;

/**
* Config
*
* @var ConfigInterface
*/
private $config;

/**
* Json Serializer
*
* @var Json
*/
private $json;

/**
* ConfirmationPopup constructor.
* @param Template\Context $context
* @param StoreOptions $storeOptions
* @param ConfigInterface $config
* @param Json $json
* @param array $data
*/
public function __construct(
Template\Context $context,
StoreOptions $storeOptions,
ConfigInterface $config,
Json $json,
array $data = []
) {
parent::__construct($context, $data);
$this->storeOptions = $storeOptions;
$this->config = $config;
$this->json = $json;
}

/**
* @return string
*/
public function getJsLayout()
{
$layout = $this->json->unserialize(parent::getJsLayout());
$showStoreViewOptions = $this->config->isStoreManualChoiceEnabled();

$layout['components']['lac-confirmation-popup']['title'] = $showStoreViewOptions
? __('Login as Customer: Select Store View')
: __('You are about to Login as Customer');
$layout['components']['lac-confirmation-popup']['content'] = __('Actions taken while in "Login as Customer" will affect actual customer data.');

$layout['components']['lac-confirmation-popup']['showStoreViewOptions'] = $showStoreViewOptions;
$layout['components']['lac-confirmation-popup']['storeViewOptions'] = $showStoreViewOptions
? $this->storeOptions->toOptionArray()
: [];

return $this->json->serialize($layout);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ public function execute(): ResultInterface
return $resultRedirect->setPath('customer/index/index');
}

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

$adminUser = $this->authSession->getUser();
Expand Down

This file was deleted.

22 changes: 13 additions & 9 deletions app/code/Magento/LoginAsCustomerUi/Plugin/Button/ToolbarPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,35 @@
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;

/**
* Plugin for \Magento\Backend\Block\Widget\Button\Toolbar.
*/
class ToolbarPlugin
{
/**
* @var \Magento\Framework\AuthorizationInterface
* @var AuthorizationInterface
*/
private $authorization;

/**
* @var \Magento\Framework\UrlInterface
* @var Escaper
*/
private $url;
private $escaper;

/**
* ToolbarPlugin constructor.
* @param \Magento\Framework\AuthorizationInterface $authorization
* @param \Magento\Framework\UrlInterface $url
* @param AuthorizationInterface $authorization
* @param Escaper $escaper
*/
public function __construct(
\Magento\Framework\AuthorizationInterface $authorization,
\Magento\Framework\UrlInterface $url
AuthorizationInterface $authorization,
Escaper $escaper
) {
$this->authorization = $authorization;
$this->url = $url;
$this->escaper = $escaper;
}

/**
Expand Down Expand Up @@ -74,7 +76,9 @@ public function beforePushButtons(
'guest_to_customer',
[
'label' => __('Login As Customer'),
'onclick' => 'window.open(\'' . $buttonUrl . '\')',
'onclick' => 'window.lacConfirmationPopup("'
. $this->escaper->escapeHtml($this->escaper->escapeJs($buttonUrl))
. '")',
'class' => 'reset'
],
-1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

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

use Magento\Customer\Block\Adminhtml\Edit\GenericButton;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
use Magento\Framework\Escaper;
use Magento\Framework\Registry;
use Magento\Backend\Block\Widget\Context;
use Magento\Customer\Block\Adminhtml\Edit\GenericButton;

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

/**
* @param \Magento\Backend\Block\Widget\Context $context
* @param \Magento\Framework\Registry $registry
* Escaper
*
* @var Escaper
*/
private $escaper;

/**
* @param Context $context
* @param Registry $registry
*/
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
\Magento\Framework\Registry $registry
Context $context,
Registry $registry
) {
parent::__construct($context, $registry);
$this->authorization = $context->getAuthorization();
$this->escaper = $context->getEscaper();
}

/**
Expand All @@ -44,8 +55,9 @@ public function getButtonData(): array
$data = [
'label' => __('Login As Customer'),
'class' => 'login login-button',
'on_click' => 'window.open( \'' . $this->getLoginUrl() .
'\')',
'on_click' => 'window.lacConfirmationPopup("'
. $this->escaper->escapeHtml($this->escaper->escapeJs($this->getLoginUrl()))
. '")',
'sort_order' => 70,
];
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
<update handle="loginascustomer_confirmation_popup" />
</layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
<update handle="loginascustomer_confirmation_popup" />
</layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
<referenceContainer name="content">
<block class="Magento\LoginAsCustomerUi\Block\Adminhtml\ConfirmationPopup" name="lac.confirmation.popup" template="Magento_LoginAsCustomerUi::confirmation-popup.phtml">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="lac-confirmation-popup" xsi:type="array">
<item name="component" xsi:type="string">Magento_LoginAsCustomerUi/js/confirmation-popup</item>
</item>
</item>
</argument>
</arguments>
</block>
</referenceContainer>
</layout>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
<update handle="loginascustomer_confirmation_popup" />
</layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
<update handle="loginascustomer_confirmation_popup" />
</layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
<update handle="loginascustomer_confirmation_popup" />
</layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/** @var \Magento\LoginAsCustomerUi\Block\Adminhtml\ConfirmationPopup $block */
?>

<script type="text/x-magento-init">
{
"*": {
"Magento_Ui/js/core/app": <?php /* @escapeNotVerified */ echo $block->getJsLayout();?>
}
}
</script>
Loading

0 comments on commit dc7ba27

Please sign in to comment.