如果客户从结帐页面登录,如何将客户重定向到购物车页面?

时间:2019-03-28 10:40:08

标签: magento2 checkout

当客户在结帐页面上登录时,然后重定向到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;
}

0 个答案:

没有答案