Skip to content

Commit

Permalink
Merge pull request #148 from ihorvansach/magento2-login-as-customer/i…
Browse files Browse the repository at this point in the history
…ssues/102

magento2-login-as-customer/issues/102
  • Loading branch information
naydav authored May 11, 2020
2 parents 8694e0b + 185772d commit 0bbaf70
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Login extends Action implements HttpGetActionInterface, HttpPostActionInterface
class Login extends Action implements HttpGetActionInterface
{
/**
* Authorization level of a basic admin session
Expand Down Expand Up @@ -140,7 +140,7 @@ public function execute(): ResultInterface
}

try {
$this->customerRepository->getById($customerId);
$customer = $this->customerRepository->getById($customerId);
} catch (NoSuchEntityException $e) {
$this->messageManager->addErrorMessage(__('Customer with this ID are no longer exist.'));
return $resultRedirect->setPath('customer/index/index');
Expand Down Expand Up @@ -170,6 +170,10 @@ public function execute(): ResultInterface
$this->deleteExpiredAuthenticationData->execute($userId);
$secret = $this->saveAuthenticationData->execute($authenticationData);

if (empty($storeId)) {
$storeId = (int)$customer->getStoreId();
}

$redirectUrl = $this->getLoginProceedRedirectUrl($secret, $storeId);
$resultRedirect->setUrl($redirectUrl);
return $resultRedirect;
Expand All @@ -185,7 +189,7 @@ public function execute(): ResultInterface
*/
private function getLoginProceedRedirectUrl(string $secret, ?int $storeId): string
{
if (null === $storeId) {
if (empty($storeId)) {
$store = $this->storeManager->getDefaultStoreView();
} else {
$store = $this->storeManager->getStore($storeId);
Expand Down

0 comments on commit 0bbaf70

Please sign in to comment.