Skip to content

Set of improvements for LoginAsCustomer modules #29688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions app/code/Magento/LoginAsCustomer/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,9 @@
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\LoginAsCustomerApi\Api\ConfigInterface;

/**
* @inheritdoc
*/
class Config implements ConfigInterface
{
/**
* Extension config path
*/
private const XML_PATH_ENABLED
= 'login_as_customer/general/enabled';
private const XML_PATH_ENABLED = 'login_as_customer/general/enabled';
private const XML_PATH_STORE_VIEW_MANUAL_CHOICE_ENABLED
= 'login_as_customer/general/store_view_manual_choice_enabled';
private const XML_PATH_AUTHENTICATION_EXPIRATION_TIME
Expand All @@ -33,9 +26,8 @@ class Config implements ConfigInterface
/**
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
ScopeConfigInterface $scopeConfig
) {
public function __construct(ScopeConfigInterface $scopeConfig)
{
$this->scopeConfig = $scopeConfig;
}

Expand All @@ -44,15 +36,15 @@ public function __construct(
*/
public function isEnabled(): bool
{
return (bool)$this->scopeConfig->getValue(self::XML_PATH_ENABLED);
return $this->scopeConfig->isSetFlag(self::XML_PATH_ENABLED);
}

/**
* @inheritdoc
*/
public function isStoreManualChoiceEnabled(): bool
{
return (bool)$this->scopeConfig->getValue(self::XML_PATH_STORE_VIEW_MANUAL_CHOICE_ENABLED);
return $this->scopeConfig->isSetFlag(self::XML_PATH_STORE_VIEW_MANUAL_CHOICE_ENABLED);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@
*/
class StoreViewLogin implements \Magento\Framework\Data\OptionSourceInterface
{
/**
* @const int
*/
private const AUTODETECT = 0;

/**
* @const int
*/
private const MANUAL = 1;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Magento\LoginAsCustomerAdminUi\Plugin\Button;

use Magento\Backend\Block\Widget\Button\ButtonList;
use Magento\Backend\Block\Widget\Button\ToolbarInterface;
use Magento\Framework\AuthorizationInterface;
use Magento\Framework\Escaper;
use Magento\Framework\View\Element\AbstractBlock;
Expand Down Expand Up @@ -61,13 +62,13 @@ public function __construct(
/**
* Add Login as Customer button.
*
* @param \Magento\Backend\Block\Widget\Button\ToolbarInterface $subject
* @param \Magento\Framework\View\Element\AbstractBlock $context
* @param \Magento\Backend\Block\Widget\Button\ButtonList $buttonList
* @param ToolbarInterface $subject
* @param AbstractBlock $context
* @param ButtonList $buttonList
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforePushButtons(
\Magento\Backend\Block\Widget\Button\ToolbarInterface $subject,
ToolbarInterface $subject,
AbstractBlock $context,
ButtonList $buttonList
): void {
Expand Down Expand Up @@ -97,18 +98,17 @@ public function beforePushButtons(
*/
private function getOrder(string $nameInLayout, AbstractBlock $context)
{
$order = null;

if ('sales_order_edit' == $nameInLayout) {
$order = $context->getOrder();
} elseif ('sales_invoice_view' == $nameInLayout) {
$order = $context->getInvoice()->getOrder();
} elseif ('sales_shipment_view' == $nameInLayout) {
$order = $context->getShipment()->getOrder();
} elseif ('sales_creditmemo_view' == $nameInLayout) {
$order = $context->getCreditmemo()->getOrder();
switch ($nameInLayout) {
case 'sales_order_edit':
return $context->getOrder();
case 'sales_invoice_view':
return $context->getInvoice()->getOrder();
case 'sales_shipment_view':
return $context->getShipment()->getOrder();
case 'sales_creditmemo_view':
return $context->getCreditmemo()->getOrder();
}

return $order;
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@
class NotAllowedPopup extends Template
{
/**
* Config
*
* @var ConfigInterface
*/
private $config;

/**
* Json Serializer
*
* @var Json
*/
private $json;
Expand Down
3 changes: 0 additions & 3 deletions app/code/Magento/LoginAsCustomerAssistance/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
*/
class Config implements ConfigInterface
{
/**
* Extension config path
*/
private const XML_PATH_SHOPPING_ASSISTANCE_CHECKBOX_TITLE
= 'login_as_customer/general/shopping_assistance_checkbox_title';
private const XML_PATH_SHOPPING_ASSISTANCE_CHECKBOX_TOOLTIP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Framework\App\RequestInterface;
use Magento\Framework\AuthorizationInterface;
use Magento\Framework\Message\MessageInterface;
use Magento\Framework\Validator\Exception as ValidatorException;
use Magento\LoginAsCustomerAssistance\Api\IsAssistanceEnabledInterface;
use Magento\LoginAsCustomerAssistance\Model\ResourceModel\GetLoginAsCustomerAssistanceAllowed;

Expand Down Expand Up @@ -48,7 +49,7 @@ public function __construct(
* @param RequestInterface $request
* @param null|string $scope
* @param bool $scopeOnly
* @throws \Magento\Framework\Validator\Exception
* @throws ValidatorException
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeExtractData(
Expand All @@ -74,11 +75,7 @@ public function beforeExtractData(
],
];

throw new \Magento\Framework\Validator\Exception(
null,
null,
$errorMessages
);
throw new ValidatorException(null, null, $errorMessages);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,20 @@ public function __construct(
* Add assistance_allowed extension attribute value to Customer instance.
*
* @param CustomerExtractor $subject
* @param callable $proceed
* @param CustomerInterface $customer
* @param string $formCode
* @param RequestInterface $request
* @param array $attributeValues
* @return CustomerInterface
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundExtract(
public function afterExtract(
CustomerExtractor $subject,
callable $proceed,
CustomerInterface $customer,
string $formCode,
RequestInterface $request,
array $attributeValues = []
) {
/** @var CustomerInterface $customer */
$customer = $proceed(
$formCode,
$request,
$attributeValues
);

$assistanceAllowedStatus = $request->getParam('assistance_allowed');
if (!empty($assistanceAllowedStatus)) {
$extensionAttributes = $customer->getExtensionAttributes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ public function __construct(
*/
public function beforeExecute(ActionInterface $subject)
{
if ($this->config->isEnabled()) {
$adminId = $this->getLoggedAsCustomerAdminId->execute();
$customerId = (int)$this->session->getCustomerId();
if ($adminId && $customerId) {
if (!$this->isLoginAsCustomerSessionActive->execute($customerId, $adminId)) {
$this->session->clearStorage();
$this->session->expireSessionCookie();
$this->session->regenerateId();
}
if (!$this->config->isEnabled()) {
return;
}

$adminId = $this->getLoggedAsCustomerAdminId->execute();
$customerId = (int)$this->session->getCustomerId();
if ($adminId && $customerId) {
if (!$this->isLoginAsCustomerSessionActive->execute($customerId, $adminId)) {
$this->session->clearStorage();
$this->session->expireSessionCookie();
$this->session->regenerateId();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(
public function afterIsEnabled(Config $subject, $isEnabled): bool
{
if ($isEnabled) {
$disable = $this->scopeConfig->getValue(
$disable = $this->scopeConfig->isSetFlag(
'login_as_customer/general/disable_page_cache',
ScopeInterface::SCOPE_STORE
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ class AdminAddCommentOnOrderPlacementPlugin
/**
* @param Session $session
*/
public function __construct(
Session $session
) {
public function __construct(Session $session)
{
$this->userSession = $session;
}

Expand Down