-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5961 from magento-engcom/magento2-login-as-custom…
…er#144 "Login as Customer" functionality should be enabled by default
- Loading branch information
Showing
35 changed files
with
898 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
app/code/Magento/LoginAsCustomer/Model/GetLoggedAsCustomerAdminId.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\LoginAsCustomer\Model; | ||
|
||
use Magento\Customer\Model\Session; | ||
use Magento\LoginAsCustomerApi\Api\GetLoggedAsCustomerAdminIdInterface; | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse) | ||
*/ | ||
class GetLoggedAsCustomerAdminId implements GetLoggedAsCustomerAdminIdInterface | ||
{ | ||
/** | ||
* @var Session | ||
*/ | ||
private $session; | ||
|
||
/** | ||
* @param Session $session | ||
*/ | ||
public function __construct(Session $session) | ||
{ | ||
$this->session = $session; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute(): int | ||
{ | ||
return (int)$this->session->getLoggedAsCustomerAdmindId(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/code/Magento/LoginAsCustomer/Model/GetLoggedAsCustomerCustomerId.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\LoginAsCustomer\Model; | ||
|
||
use Magento\Backend\Model\Auth\Session; | ||
use Magento\LoginAsCustomerApi\Api\GetLoggedAsCustomerCustomerIdInterface; | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse) | ||
*/ | ||
class GetLoggedAsCustomerCustomerId implements GetLoggedAsCustomerCustomerIdInterface | ||
{ | ||
/** | ||
* @var Session | ||
*/ | ||
private $session; | ||
|
||
/** | ||
* @param Session $session | ||
*/ | ||
public function __construct(Session $session) | ||
{ | ||
$this->session = $session; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute(): int | ||
{ | ||
return (int)$this->session->getLoggedAsCustomerCustomerId(); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
app/code/Magento/LoginAsCustomer/Model/IsLoginAsCustomerEnabledForCustomerChain.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\LoginAsCustomer\Model; | ||
|
||
use Magento\LoginAsCustomerApi\Api\ConfigInterface; | ||
use Magento\LoginAsCustomerApi\Api\Data\IsLoginAsCustomerEnabledForCustomerResultInterface; | ||
use Magento\LoginAsCustomerApi\Api\IsLoginAsCustomerEnabledForCustomerInterface; | ||
use Magento\LoginAsCustomerApi\Model\IsLoginAsCustomerEnabledForCustomerResolverInterface; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
class IsLoginAsCustomerEnabledForCustomerChain implements IsLoginAsCustomerEnabledForCustomerInterface | ||
{ | ||
/** | ||
* @var ConfigInterface | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @var IsLoginAsCustomerEnabledForCustomerResultFactory | ||
*/ | ||
private $resultFactory; | ||
|
||
/** | ||
* @var IsLoginAsCustomerEnabledForCustomerResultInterface[] | ||
*/ | ||
private $resolvers; | ||
|
||
/** | ||
* @param ConfigInterface $config | ||
* @param IsLoginAsCustomerEnabledForCustomerResultFactory $resultFactory | ||
* @param array $resolvers | ||
*/ | ||
public function __construct( | ||
ConfigInterface $config, | ||
IsLoginAsCustomerEnabledForCustomerResultFactory $resultFactory, | ||
array $resolvers = [] | ||
) { | ||
$this->config = $config; | ||
$this->resultFactory = $resultFactory; | ||
$this->resolvers = $resolvers; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute(int $customerId): IsLoginAsCustomerEnabledForCustomerResultInterface | ||
{ | ||
$messages = [[]]; | ||
/** @var IsLoginAsCustomerEnabledForCustomerResultInterface $resolver */ | ||
foreach ($this->resolvers as $resolver) { | ||
$resolverResult = $resolver->execute($customerId); | ||
if (!$resolverResult->isEnabled()) { | ||
$messages[] = $resolverResult->getMessages(); | ||
} | ||
} | ||
|
||
return $this->resultFactory->create(['messages' => array_merge(...$messages)]); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
app/code/Magento/LoginAsCustomer/Model/IsLoginAsCustomerEnabledForCustomerResult.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\LoginAsCustomer\Model; | ||
|
||
use Magento\LoginAsCustomerApi\Api\Data\IsLoginAsCustomerEnabledForCustomerResultInterface; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
class IsLoginAsCustomerEnabledForCustomerResult implements IsLoginAsCustomerEnabledForCustomerResultInterface | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private $messages; | ||
|
||
/** | ||
* @param array $messages | ||
*/ | ||
public function __construct(array $messages = []) | ||
{ | ||
$this->messages = $messages; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function isEnabled(): bool | ||
{ | ||
return empty($this->messages); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getMessages(): array | ||
{ | ||
return $this->messages; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setMessages(array $messages): void | ||
{ | ||
$this->messages = $messages; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/code/Magento/LoginAsCustomer/Model/Resolver/IsLoginAsCustomerEnabledResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\LoginAsCustomer\Model\Resolver; | ||
|
||
use Magento\LoginAsCustomer\Model\IsLoginAsCustomerEnabledForCustomerResultFactory; | ||
use Magento\LoginAsCustomerApi\Api\ConfigInterface; | ||
use Magento\LoginAsCustomerApi\Api\Data\IsLoginAsCustomerEnabledForCustomerResultInterface; | ||
use Magento\LoginAsCustomerApi\Api\IsLoginAsCustomerEnabledForCustomerInterface; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
class IsLoginAsCustomerEnabledResolver implements IsLoginAsCustomerEnabledForCustomerInterface | ||
{ | ||
/** | ||
* @var ConfigInterface | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @var IsLoginAsCustomerEnabledForCustomerResultFactory | ||
*/ | ||
private $resultFactory; | ||
|
||
/** | ||
* @param ConfigInterface $config | ||
* @param IsLoginAsCustomerEnabledForCustomerResultFactory $resultFactory | ||
*/ | ||
public function __construct( | ||
ConfigInterface $config, | ||
IsLoginAsCustomerEnabledForCustomerResultFactory $resultFactory | ||
) { | ||
$this->config = $config; | ||
$this->resultFactory = $resultFactory; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute(int $customerId): IsLoginAsCustomerEnabledForCustomerResultInterface | ||
{ | ||
$messages = []; | ||
if (!$this->config->isEnabled()) { | ||
$messages[] = __('Login as Customer is disabled.'); | ||
} | ||
|
||
return $this->resultFactory->create(['messages' => $messages]); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/code/Magento/LoginAsCustomer/Model/SetLoggedAsCustomerAdminId.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\LoginAsCustomer\Model; | ||
|
||
use Magento\Customer\Model\Session; | ||
use Magento\LoginAsCustomerApi\Api\SetLoggedAsCustomerAdminIdInterface; | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse) | ||
*/ | ||
class SetLoggedAsCustomerAdminId implements SetLoggedAsCustomerAdminIdInterface | ||
{ | ||
/** | ||
* @var Session | ||
*/ | ||
private $session; | ||
|
||
/** | ||
* @param Session $session | ||
*/ | ||
public function __construct(Session $session) | ||
{ | ||
$this->session = $session; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute(int $adminId): void | ||
{ | ||
$this->session->setLoggedAsCustomerAdmindId($adminId); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/code/Magento/LoginAsCustomer/Model/SetLoggedAsCustomerCustomerId.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\LoginAsCustomer\Model; | ||
|
||
use Magento\Backend\Model\Auth\Session; | ||
use Magento\LoginAsCustomerApi\Api\SetLoggedAsCustomerCustomerIdInterface; | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse) | ||
*/ | ||
class SetLoggedAsCustomerCustomerId implements SetLoggedAsCustomerCustomerIdInterface | ||
{ | ||
/** | ||
* @var Session | ||
*/ | ||
private $session; | ||
|
||
/** | ||
* @param Session $session | ||
*/ | ||
public function __construct(Session $session) | ||
{ | ||
$this->session = $session; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute(int $customerId): void | ||
{ | ||
$this->session->setLoggedAsCustomerCustomerId($customerId); | ||
} | ||
} |
Oops, something went wrong.