Skip to content

Commit

Permalink
[Magento Community Engineering] Community Contributions - 2.4-develop
Browse files Browse the repository at this point in the history
 - merged latest code from mainline branch
  • Loading branch information
magento-engcom-team authored Sep 14, 2020
2 parents 1e3bef5 + 468128c commit c3b95fd
Show file tree
Hide file tree
Showing 27 changed files with 313 additions and 315 deletions.
10 changes: 5 additions & 5 deletions app/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
#ini_set('display_errors', 1);

/* PHP version validation */
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 70103) {
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 70300) {
if (PHP_SAPI == 'cli') {
echo 'Magento supports PHP 7.1.3 or later. ' .
'Please read https://devdocs.magento.com/guides/v2.3/install-gde/system-requirements-tech.html';
echo 'Magento supports PHP 7.3.0 or later. ' .
'Please read https://devdocs.magento.com/guides/v2.4/install-gde/system-requirements-tech.html';
} else {
echo <<<HTML
<div style="font:12px/1.35em arial, helvetica, sans-serif;">
<p>Magento supports PHP 7.1.3 or later. Please read
<a target="_blank" href="https://devdocs.magento.com/guides/v2.3/install-gde/system-requirements-tech.html">
<p>Magento supports PHP 7.3.0 or later. Please read
<a target="_blank" href="https://devdocs.magento.com/guides/v2.4/install-gde/system-requirements-tech.html">
Magento System Requirements</a>.
</div>
HTML;
Expand Down
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
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AssertStorefrontStickyLoginAsCustomerNotificationBannerActionGroup">
<annotations>
<description>Verify Sticky Login as Customer notification banner present on page.</description>
</annotations>
<arguments>
<argument name="customerFullName" type="string"/>
<argument name="websiteName" type="string" defaultValue="Main Website"/>
</arguments>

<waitForElementVisible selector="{{StorefrontLoginAsCustomerNotificationSection.notificationText}}" stepKey="waitForNotificationBanner"/>
<see selector="{{StorefrontLoginAsCustomerNotificationSection.notificationText}}"
userInput="You are connected as {{customerFullName}} on {{websiteName}}"
stepKey="assertCorrectNotificationBannerMessage"/>
<seeElement selector="{{StorefrontLoginAsCustomerNotificationSection.closeLink}}"
stepKey="assertCloseNotificationBannerPresent"/>
<executeJS function="window.scrollTo(0,document.body.scrollHeight);" stepKey="scrollToBottomOfPage"/>
<see selector="{{StorefrontLoginAsCustomerNotificationSection.notificationText}}"
userInput="You are connected as {{customerFullName}} on {{websiteName}}"
stepKey="assertCorrectNotificationBannerMessageAfterScroll"/>
<seeElement selector="{{StorefrontLoginAsCustomerNotificationSection.closeLink}}"
stepKey="assertCloseNotificationBannerPresentAfterScroll"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="StorefrontStickyLoginAsCustomerNotificationBannerTest">
<annotations>
<features value="Login as Customer"/>
<useCaseId value="https://github.com/magento/magento2/issues/29354"/>
<stories value="Availability of sticky UI elements if module enable/disable"/>
<title value="Sticky Notification Banner is present on Storefront page"/>
<description
value="Verify that Sticky Notification Banner is present on page if 'Login as customer' functionality used"/>
<testCaseId value=""/>
<group value="login_as_customer"/>
<severity value="CRITICAL"/>
</annotations>
<before>
<magentoCLI command="config:set {{LoginAsCustomerConfigDataEnabled.path}} 1"
stepKey="enableLoginAsCustomer"/>
<actionGroup ref="CliCacheCleanActionGroup" stepKey="cleanConfigCache">
<argument name="tags" value="config"/>
</actionGroup>
<createData entity="Simple_US_Customer_Assistance_Allowed" stepKey="createCustomer"/>
<actionGroup ref="AdminLoginActionGroup" stepKey="login"/>
</before>

<after>
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
<magentoCLI command="config:set {{LoginAsCustomerConfigDataEnabled.path}} 0"
stepKey="disableLoginAsCustomer"/>
<actionGroup ref="CliCacheCleanActionGroup" stepKey="cleanConfigCache">
<argument name="tags" value="config"/>
</actionGroup>
</after>

<actionGroup ref="AdminLoginAsCustomerLoginFromCustomerPageActionGroup" stepKey="loginAsCustomerFromCustomerPage">
<argument name="customerId" value="$$createCustomer.id$$"/>
</actionGroup>

<actionGroup ref="AssertStorefrontStickyLoginAsCustomerNotificationBannerActionGroup" stepKey="assertStickyNotificationBanner">
<argument name="customerFullName" value="$$createCustomer.firstname$$ $$createCustomer.lastname$$"/>
</actionGroup>

<actionGroup ref="StorefrontSignOutNotificationBannerAndCloseTabActionGroup" stepKey="signOutAndCloseTab"/>
</test>
</tests>
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 @@ -11,7 +11,9 @@
$viewFileUrl = $block->getViewFileUrl('Magento_LoginAsCustomerFrontendUi::images/magento-icon.svg');
?>
<?php if ($block->getConfig()->isEnabled()): ?>
<div data-bind="scope: 'loginAsCustomer'" >
<div class="lac-notification-sticky"
data-mage-init='{"sticky":{"container": "body"}}'
data-bind="scope: 'loginAsCustomer'" >
<div class="lac-notification clearfix" data-bind="visible: isVisible" style="display: none">
<div class="top-container">
<div class="lac-notification-icon wrapper">
Expand Down
Loading

0 comments on commit c3b95fd

Please sign in to comment.