diff --git a/app/code/Magento/LoginAsCustomer/Model/Config.php b/app/code/Magento/LoginAsCustomer/Model/Config.php index 2cfafa6ac09a3..bec9527c65f95 100644 --- a/app/code/Magento/LoginAsCustomer/Model/Config.php +++ b/app/code/Magento/LoginAsCustomer/Model/Config.php @@ -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 @@ -33,9 +26,8 @@ class Config implements ConfigInterface /** * @param ScopeConfigInterface $scopeConfig */ - public function __construct( - ScopeConfigInterface $scopeConfig - ) { + public function __construct(ScopeConfigInterface $scopeConfig) + { $this->scopeConfig = $scopeConfig; } @@ -44,7 +36,7 @@ public function __construct( */ public function isEnabled(): bool { - return (bool)$this->scopeConfig->getValue(self::XML_PATH_ENABLED); + return $this->scopeConfig->isSetFlag(self::XML_PATH_ENABLED); } /** @@ -52,7 +44,7 @@ public function isEnabled(): bool */ 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); } /** diff --git a/app/code/Magento/LoginAsCustomerAdminUi/Model/Config/Source/StoreViewLogin.php b/app/code/Magento/LoginAsCustomerAdminUi/Model/Config/Source/StoreViewLogin.php index 265c4fedb722d..9d14a4b44d10b 100644 --- a/app/code/Magento/LoginAsCustomerAdminUi/Model/Config/Source/StoreViewLogin.php +++ b/app/code/Magento/LoginAsCustomerAdminUi/Model/Config/Source/StoreViewLogin.php @@ -12,14 +12,7 @@ */ class StoreViewLogin implements \Magento\Framework\Data\OptionSourceInterface { - /** - * @const int - */ private const AUTODETECT = 0; - - /** - * @const int - */ private const MANUAL = 1; /** diff --git a/app/code/Magento/LoginAsCustomerAdminUi/Plugin/Button/ToolbarPlugin.php b/app/code/Magento/LoginAsCustomerAdminUi/Plugin/Button/ToolbarPlugin.php index c67b0d9dd5273..2cdcd5723df4b 100644 --- a/app/code/Magento/LoginAsCustomerAdminUi/Plugin/Button/ToolbarPlugin.php +++ b/app/code/Magento/LoginAsCustomerAdminUi/Plugin/Button/ToolbarPlugin.php @@ -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; @@ -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 { @@ -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; } } diff --git a/app/code/Magento/LoginAsCustomerAssistance/Block/Adminhtml/NotAllowedPopup.php b/app/code/Magento/LoginAsCustomerAssistance/Block/Adminhtml/NotAllowedPopup.php index 547be1de5a008..b98ea203057b1 100644 --- a/app/code/Magento/LoginAsCustomerAssistance/Block/Adminhtml/NotAllowedPopup.php +++ b/app/code/Magento/LoginAsCustomerAssistance/Block/Adminhtml/NotAllowedPopup.php @@ -19,15 +19,11 @@ class NotAllowedPopup extends Template { /** - * Config - * * @var ConfigInterface */ private $config; /** - * Json Serializer - * * @var Json */ private $json; diff --git a/app/code/Magento/LoginAsCustomerAssistance/Model/Config.php b/app/code/Magento/LoginAsCustomerAssistance/Model/Config.php index 2fce39cd4e85e..c2244fa3a799c 100644 --- a/app/code/Magento/LoginAsCustomerAssistance/Model/Config.php +++ b/app/code/Magento/LoginAsCustomerAssistance/Model/Config.php @@ -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 diff --git a/app/code/Magento/LoginAsCustomerAssistance/Plugin/CustomerDataValidatePlugin.php b/app/code/Magento/LoginAsCustomerAssistance/Plugin/CustomerDataValidatePlugin.php index 9da329b4a3991..4bbf691e2b58e 100644 --- a/app/code/Magento/LoginAsCustomerAssistance/Plugin/CustomerDataValidatePlugin.php +++ b/app/code/Magento/LoginAsCustomerAssistance/Plugin/CustomerDataValidatePlugin.php @@ -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; @@ -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( @@ -74,11 +75,7 @@ public function beforeExtractData( ], ]; - throw new \Magento\Framework\Validator\Exception( - null, - null, - $errorMessages - ); + throw new ValidatorException(null, null, $errorMessages); } } } diff --git a/app/code/Magento/LoginAsCustomerAssistance/Plugin/CustomerExtractorPlugin.php b/app/code/Magento/LoginAsCustomerAssistance/Plugin/CustomerExtractorPlugin.php index 619036da8bb22..156d84bcae9bd 100644 --- a/app/code/Magento/LoginAsCustomerAssistance/Plugin/CustomerExtractorPlugin.php +++ b/app/code/Magento/LoginAsCustomerAssistance/Plugin/CustomerExtractorPlugin.php @@ -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(); diff --git a/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/InvalidateExpiredSessionPlugin.php b/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/InvalidateExpiredSessionPlugin.php index c1e035ac9637c..7c0682440b4dc 100644 --- a/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/InvalidateExpiredSessionPlugin.php +++ b/app/code/Magento/LoginAsCustomerFrontendUi/Plugin/InvalidateExpiredSessionPlugin.php @@ -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(); } } } diff --git a/app/code/Magento/LoginAsCustomerPageCache/Plugin/PageCache/Model/Config/DisablePageCacheIfNeededPlugin.php b/app/code/Magento/LoginAsCustomerPageCache/Plugin/PageCache/Model/Config/DisablePageCacheIfNeededPlugin.php index dabf8c62e1dee..2b98c1f6c119e 100644 --- a/app/code/Magento/LoginAsCustomerPageCache/Plugin/PageCache/Model/Config/DisablePageCacheIfNeededPlugin.php +++ b/app/code/Magento/LoginAsCustomerPageCache/Plugin/PageCache/Model/Config/DisablePageCacheIfNeededPlugin.php @@ -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 ); diff --git a/app/code/Magento/LoginAsCustomerSales/Plugin/AdminAddCommentOnOrderPlacementPlugin.php b/app/code/Magento/LoginAsCustomerSales/Plugin/AdminAddCommentOnOrderPlacementPlugin.php index 2ae982e536f49..3a27a5ef9e561 100644 --- a/app/code/Magento/LoginAsCustomerSales/Plugin/AdminAddCommentOnOrderPlacementPlugin.php +++ b/app/code/Magento/LoginAsCustomerSales/Plugin/AdminAddCommentOnOrderPlacementPlugin.php @@ -25,9 +25,8 @@ class AdminAddCommentOnOrderPlacementPlugin /** * @param Session $session */ - public function __construct( - Session $session - ) { + public function __construct(Session $session) + { $this->userSession = $session; }