Skip to content

Commit 2e021fd

Browse files
authored
ENGCOM-8052: Set of improvements for LoginAsCustomer modules #29688
2 parents f02a0f2 + db44cbc commit 2e021fd

File tree

10 files changed

+40
-71
lines changed

10 files changed

+40
-71
lines changed

app/code/Magento/LoginAsCustomer/Model/Config.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,9 @@
1010
use Magento\Framework\App\Config\ScopeConfigInterface;
1111
use Magento\LoginAsCustomerApi\Api\ConfigInterface;
1212

13-
/**
14-
* @inheritdoc
15-
*/
1613
class Config implements ConfigInterface
1714
{
18-
/**
19-
* Extension config path
20-
*/
21-
private const XML_PATH_ENABLED
22-
= 'login_as_customer/general/enabled';
15+
private const XML_PATH_ENABLED = 'login_as_customer/general/enabled';
2316
private const XML_PATH_STORE_VIEW_MANUAL_CHOICE_ENABLED
2417
= 'login_as_customer/general/store_view_manual_choice_enabled';
2518
private const XML_PATH_AUTHENTICATION_EXPIRATION_TIME
@@ -33,9 +26,8 @@ class Config implements ConfigInterface
3326
/**
3427
* @param ScopeConfigInterface $scopeConfig
3528
*/
36-
public function __construct(
37-
ScopeConfigInterface $scopeConfig
38-
) {
29+
public function __construct(ScopeConfigInterface $scopeConfig)
30+
{
3931
$this->scopeConfig = $scopeConfig;
4032
}
4133

@@ -44,15 +36,15 @@ public function __construct(
4436
*/
4537
public function isEnabled(): bool
4638
{
47-
return (bool)$this->scopeConfig->getValue(self::XML_PATH_ENABLED);
39+
return $this->scopeConfig->isSetFlag(self::XML_PATH_ENABLED);
4840
}
4941

5042
/**
5143
* @inheritdoc
5244
*/
5345
public function isStoreManualChoiceEnabled(): bool
5446
{
55-
return (bool)$this->scopeConfig->getValue(self::XML_PATH_STORE_VIEW_MANUAL_CHOICE_ENABLED);
47+
return $this->scopeConfig->isSetFlag(self::XML_PATH_STORE_VIEW_MANUAL_CHOICE_ENABLED);
5648
}
5749

5850
/**

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@
1212
*/
1313
class StoreViewLogin implements \Magento\Framework\Data\OptionSourceInterface
1414
{
15-
/**
16-
* @const int
17-
*/
1815
private const AUTODETECT = 0;
19-
20-
/**
21-
* @const int
22-
*/
2316
private const MANUAL = 1;
2417

2518
/**

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\LoginAsCustomerAdminUi\Plugin\Button;
99

1010
use Magento\Backend\Block\Widget\Button\ButtonList;
11+
use Magento\Backend\Block\Widget\Button\ToolbarInterface;
1112
use Magento\Framework\AuthorizationInterface;
1213
use Magento\Framework\Escaper;
1314
use Magento\Framework\View\Element\AbstractBlock;
@@ -61,13 +62,13 @@ public function __construct(
6162
/**
6263
* Add Login as Customer button.
6364
*
64-
* @param \Magento\Backend\Block\Widget\Button\ToolbarInterface $subject
65-
* @param \Magento\Framework\View\Element\AbstractBlock $context
66-
* @param \Magento\Backend\Block\Widget\Button\ButtonList $buttonList
65+
* @param ToolbarInterface $subject
66+
* @param AbstractBlock $context
67+
* @param ButtonList $buttonList
6768
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
6869
*/
6970
public function beforePushButtons(
70-
\Magento\Backend\Block\Widget\Button\ToolbarInterface $subject,
71+
ToolbarInterface $subject,
7172
AbstractBlock $context,
7273
ButtonList $buttonList
7374
): void {
@@ -97,18 +98,17 @@ public function beforePushButtons(
9798
*/
9899
private function getOrder(string $nameInLayout, AbstractBlock $context)
99100
{
100-
$order = null;
101-
102-
if ('sales_order_edit' == $nameInLayout) {
103-
$order = $context->getOrder();
104-
} elseif ('sales_invoice_view' == $nameInLayout) {
105-
$order = $context->getInvoice()->getOrder();
106-
} elseif ('sales_shipment_view' == $nameInLayout) {
107-
$order = $context->getShipment()->getOrder();
108-
} elseif ('sales_creditmemo_view' == $nameInLayout) {
109-
$order = $context->getCreditmemo()->getOrder();
101+
switch ($nameInLayout) {
102+
case 'sales_order_edit':
103+
return $context->getOrder();
104+
case 'sales_invoice_view':
105+
return $context->getInvoice()->getOrder();
106+
case 'sales_shipment_view':
107+
return $context->getShipment()->getOrder();
108+
case 'sales_creditmemo_view':
109+
return $context->getCreditmemo()->getOrder();
110110
}
111111

112-
return $order;
112+
return null;
113113
}
114114
}

app/code/Magento/LoginAsCustomerAssistance/Block/Adminhtml/NotAllowedPopup.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@
1919
class NotAllowedPopup extends Template
2020
{
2121
/**
22-
* Config
23-
*
2422
* @var ConfigInterface
2523
*/
2624
private $config;
2725

2826
/**
29-
* Json Serializer
30-
*
3127
* @var Json
3228
*/
3329
private $json;

app/code/Magento/LoginAsCustomerAssistance/Model/Config.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
*/
1717
class Config implements ConfigInterface
1818
{
19-
/**
20-
* Extension config path
21-
*/
2219
private const XML_PATH_SHOPPING_ASSISTANCE_CHECKBOX_TITLE
2320
= 'login_as_customer/general/shopping_assistance_checkbox_title';
2421
private const XML_PATH_SHOPPING_ASSISTANCE_CHECKBOX_TOOLTIP

app/code/Magento/LoginAsCustomerAssistance/Plugin/CustomerDataValidatePlugin.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\App\RequestInterface;
1212
use Magento\Framework\AuthorizationInterface;
1313
use Magento\Framework\Message\MessageInterface;
14+
use Magento\Framework\Validator\Exception as ValidatorException;
1415
use Magento\LoginAsCustomerAssistance\Api\IsAssistanceEnabledInterface;
1516
use Magento\LoginAsCustomerAssistance\Model\ResourceModel\GetLoginAsCustomerAssistanceAllowed;
1617

@@ -48,7 +49,7 @@ public function __construct(
4849
* @param RequestInterface $request
4950
* @param null|string $scope
5051
* @param bool $scopeOnly
51-
* @throws \Magento\Framework\Validator\Exception
52+
* @throws ValidatorException
5253
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5354
*/
5455
public function beforeExtractData(
@@ -74,11 +75,7 @@ public function beforeExtractData(
7475
],
7576
];
7677

77-
throw new \Magento\Framework\Validator\Exception(
78-
null,
79-
null,
80-
$errorMessages
81-
);
78+
throw new ValidatorException(null, null, $errorMessages);
8279
}
8380
}
8481
}

app/code/Magento/LoginAsCustomerAssistance/Plugin/CustomerExtractorPlugin.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,20 @@ public function __construct(
3535
* Add assistance_allowed extension attribute value to Customer instance.
3636
*
3737
* @param CustomerExtractor $subject
38-
* @param callable $proceed
38+
* @param CustomerInterface $customer
3939
* @param string $formCode
4040
* @param RequestInterface $request
4141
* @param array $attributeValues
4242
* @return CustomerInterface
4343
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4444
*/
45-
public function aroundExtract(
45+
public function afterExtract(
4646
CustomerExtractor $subject,
47-
callable $proceed,
47+
CustomerInterface $customer,
4848
string $formCode,
4949
RequestInterface $request,
5050
array $attributeValues = []
5151
) {
52-
/** @var CustomerInterface $customer */
53-
$customer = $proceed(
54-
$formCode,
55-
$request,
56-
$attributeValues
57-
);
58-
5952
$assistanceAllowedStatus = $request->getParam('assistance_allowed');
6053
if (!empty($assistanceAllowedStatus)) {
6154
$extensionAttributes = $customer->getExtensionAttributes();

app/code/Magento/LoginAsCustomerFrontendUi/Plugin/InvalidateExpiredSessionPlugin.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,17 @@ public function __construct(
6565
*/
6666
public function beforeExecute(ActionInterface $subject)
6767
{
68-
if ($this->config->isEnabled()) {
69-
$adminId = $this->getLoggedAsCustomerAdminId->execute();
70-
$customerId = (int)$this->session->getCustomerId();
71-
if ($adminId && $customerId) {
72-
if (!$this->isLoginAsCustomerSessionActive->execute($customerId, $adminId)) {
73-
$this->session->clearStorage();
74-
$this->session->expireSessionCookie();
75-
$this->session->regenerateId();
76-
}
68+
if (!$this->config->isEnabled()) {
69+
return;
70+
}
71+
72+
$adminId = $this->getLoggedAsCustomerAdminId->execute();
73+
$customerId = (int)$this->session->getCustomerId();
74+
if ($adminId && $customerId) {
75+
if (!$this->isLoginAsCustomerSessionActive->execute($customerId, $adminId)) {
76+
$this->session->clearStorage();
77+
$this->session->expireSessionCookie();
78+
$this->session->regenerateId();
7779
}
7880
}
7981
}

app/code/Magento/LoginAsCustomerPageCache/Plugin/PageCache/Model/Config/DisablePageCacheIfNeededPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct(
5454
public function afterIsEnabled(Config $subject, $isEnabled): bool
5555
{
5656
if ($isEnabled) {
57-
$disable = $this->scopeConfig->getValue(
57+
$disable = $this->scopeConfig->isSetFlag(
5858
'login_as_customer/general/disable_page_cache',
5959
ScopeInterface::SCOPE_STORE
6060
);

app/code/Magento/LoginAsCustomerSales/Plugin/AdminAddCommentOnOrderPlacementPlugin.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ class AdminAddCommentOnOrderPlacementPlugin
2525
/**
2626
* @param Session $session
2727
*/
28-
public function __construct(
29-
Session $session
30-
) {
28+
public function __construct(Session $session)
29+
{
3130
$this->userSession = $session;
3231
}
3332

0 commit comments

Comments
 (0)