Как перенаправить клиента на страницу корзины, если он авторизован на странице оформления заказа? - PullRequest
0 голосов
/ 28 марта 2019

Когда пользователь входит в систему на странице оформления заказа, затем перенаправляет на страницу корзины в magento2?
если они входят в систему со страницы других пользователей, перенаправьте страницу панели пользователя.

открытая функция execute () { if ($ this-> session-> isLoggedIn () ||! $ this-> formKeyValidator-> validate ($ this-> getRequest ())) {

        /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */

        $resultRedirect = $this->resultRedirectFactory->create();

        $resultRedirect->setPath('checkout/cart');

        return $resultRedirect;

    }

    if ($this->getRequest()->isPost()) {
        $login = $this->getRequest()->getPost('login');
        if (!empty($login['username']) && !empty($login['password'])) {
            try {
                $customer = $this->customerAccountManagement->authenticate($login['username'], $login['password']);
                $this->session->setCustomerDataAsLoggedIn($customer);
                $this->session->regenerateId();
                if ($this->getCookieManager()->getCookie('mage-cache-sessid')) {
                    $metadata = $this->getCookieMetadataFactory()->createCookieMetadata();
                    $metadata->setPath('/');
                    $this->getCookieManager()->deleteCookie('mage-cache-sessid', $metadata);
                }
                $redirectUrl = $this->accountRedirect->getRedirectCookie();
                if (!$this->getScopeConfig()->getValue('customer/startup/redirect_dashboard') && $redirectUrl) {
                    $this->accountRedirect->clearRedirectCookie();
                    $resultRedirect = $this->resultRedirectFactory->create();
                    // URL is checked to be internal in $this->_redirect->success()
                    $resultRedirect->setUrl($this->_redirect->success($redirectUrl));
                    return $resultRedirect;
                }
            } catch (EmailNotConfirmedException $e) {
                $value = $this->customerUrl->getEmailConfirmationUrl($login['username']);
                $message = __(
                    'This account is not confirmed. <a href="%1">Click here</a> to resend confirmation email.',
                    $value
                );
                $this->messageManager->addError($message);
                $this->session->setUsername($login['username']);
            } catch (UserLockedException $e) {
                $message = __(
                    'You did not sign in correctly or your account is temporarily disabled.'
                );
                $this->messageManager->addError($message);
                $this->session->setUsername($login['username']);
            } catch (AuthenticationException $e) {
                $message = __('You did not sign in correctly or your account is temporarily disabled.');
                $this->messageManager->addError($message);
                $this->session->setUsername($login['username']);
            } catch (LocalizedException $e) {
                $message = $e->getMessage();
                $this->messageManager->addError($message);
                $this->session->setUsername($login['username']);
            } catch (\Exception $e) {
                // PA DSS violation: throwing or logging an exception here can disclose customer password
                $this->messageManager->addError(
                    __('An unspecified error occurred. Please contact us for assistance.')
                );
            }
        } else {
            $this->messageManager->addError(__('A login and a password are required.'));
        }
    }

     $resultRedirect = $this->resultRedirectFactory->create();
    $resultRedirect->setPath('checkout/cart');
    return $resultRedirect;
}
...