cancel
Showing results for 
Search instead for 
Did you mean: 

Redirect to Account Dashboard During Checkout Funnel Login

Redirect to Account Dashboard During Checkout Funnel Login

I have the setting checked to redirect a customer to their account dashboard after logging in and it works fine on regular pages, but I noticed that it has no effect when someone is on the checkout page and they log in during the checkout processes. I need to redirect the customer to their dashboard when they are attempting to log in on the shopping cart page during the /checkout/cart/ funnel. Right now, it shows them their shipping options after logging in from the cart and allows them to continue the checkout process. Any solutions?

4 REPLIES

Re: Redirect to Account Dashboard During Checkout Funnel Login

Hi @mikemm,

 

I'm not sure why you should prefer to redirect the custom from the checkout but maybe you can use an observer to be executed after customer login.

At that moment you can redirect to the dashboard as you want.

 

 

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

Re: Redirect to Account Dashboard During Checkout Funnel Login

You can do it by plugin way,

 

create simple module,

app/code/Rbj/Test/etc/frontend/di.xml

 

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
     <type name="Magento\Customer\Controller\Ajax\Login">
        <plugin name="customer-login-after"
                type="Rbj\Test\Plugin\Afterlogin"/>
    </type>
</config>

Create plugin file,

 

app/code/Rbj/Test/Plugin/Afterlogin.php

 

<?php
namespace Rbj\Test\Plugin;

class Afterlogin
{
    public function __construct(
        \Magento\Framework\UrlInterface $url,
        \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
    ) {
        $this->url = $url;
        $this->resultJsonFactory = $resultJsonFactory;
    }

    public function afterExecute(\Magento\Customer\Controller\Ajax\Login $subject)
    {       
        $response['redirectUrl'] = $this->url->getUrl('customer/account/index'); 
        $resultJson = $this->resultJsonFactory->create();
        return $resultJson->setData($response);
    }
}

 Now override core magento_customer js file,

vendor/magento/module-customer/view/frontend/web/js/action/login.js to your module and keep below code,

 

 

/*global define*/
define(
    [
        'jquery',
        'mage/storage',
        'Magento_Ui/js/model/messageList',
        'Magento_Customer/js/customer-data'
    ],
    function($, storage, globalMessageList, customerData) {
        'use strict';
        var callbacks = [],
            action = function(loginData, redirectUrl, isGlobal, messageContainer) {
                messageContainer = messageContainer || globalMessageList;
                return storage.post(
                    'customer/ajax/login',
                    JSON.stringify(loginData),
                    isGlobal
                ).done(function (response) {
                    if (response.errors) {
                        messageContainer.addErrorMessage(response);
                        callbacks.forEach(function(callback) {
                            callback(loginData);
                        });
                    } else {
                        callbacks.forEach(function(callback) {
                            callback(loginData);
                        });
                        customerData.invalidate(['customer']);

                        if (response.redirectUrl) {
                            window.location.href = response.redirectUrl;
                        } else if (redirectUrl) {
                            window.location.href = redirectUrl;
                        } else {
                            location.reload();
                        }
                    }
                }).fail(function () {
                    messageContainer.addErrorMessage({'message': 'Could not authenticate. Please try again later'});
                    callbacks.forEach(function(callback) {
                        callback(loginData);
                    });
                });
            };

        action.registerLoginCallback = function(callback) {
            callbacks.push(callback);
        };
        return action;
    }
);

if issue soled, Click Kudos/Accept as solutions.

 

 

If Issue Solved, Click Kudos/Accept As solutions.

Re: Redirect to Account Dashboard During Checkout Funnel Login

Thank you for the code samples. I've tried them but haven't had any luck. No errors or redirect. Any further thoughts?

Re: Redirect to Account Dashboard During Checkout Funnel Login

this code is working for me. i have try in my local system and its working fine. can you just test from above js file by keeping  console.log(response);return false; after customerData.invalidate(['customer']); line,

 

Run upgrade and deploy command and check. any response getting or not.

 

Thanks.

If Issue Solved, Click Kudos/Accept As solutions.