I Want to check the user login status in mini cart and redirect the customer to the login page when click the proceed to checkout button in mini-cart.

How to edit the minicart.js file to achieve this?


'url': {
            'checkout': window.checkout.checkoutUrl,
            'update': window.checkout.updateItemQtyUrl,
            'remove': window.checkout.removeItemUrl,
            'loginUrl': window.checkout.customerLoginUrl,
            'isRedirectRequired': window.checkout.isRedirectRequired

How to use the if condition to check the user is logged or not logged? enter image description here

I want to forcefully redirect to the customer (registered or guest) to the login page and after logged mini cart proceeds to checkout, the button should redirect to the checkout page.


I did following changes to minicart.js

'Magento_Customer/js/model/customer',//Added this line
], function (Component, customerData, customer, $, ko, _) { //Passed argument customer
'use strict';

//checked the customer logged or not.
        var urls = window.checkout.checkoutUrl;
        var urls = window.checkout.customerLoginUrl;

esidebarInitialized = true;
        'targetElement': 'div.block.block-minicart',
        'url': {
            'checkout': urls,
            'update': window.checkout.updateItemQtyUrl,
            'remove': window.checkout.removeItemUrl,
            'loginUrl': window.checkout.customerLoginUrl,
            'isRedirectRequired': window.checkout.isRedirectRequired
................... rest of the code of the file

Unfortunately customer.isLoggedIn() this return always not logged. How to check a customer is logged or not logged?


There is two option

  1. Allow Guest Checkout is No

Stores -> Configuration -> Sales -> Checkout -> Checkout Option

Allow Guest Checkout = No

Otherwise customise to sidebar.js


line no 63

 events['click ' + this.options.button.checkout] = $.proxy(function () {
            var cart = customerData.get('cart'),
                customer = customerData.get('customer'),
                element = $(this.options.button.checkout);

            if (!customer().firstname && cart().isGuestCheckoutAllowed === false) {
                // set URL for redirect on successful login/registration. It's postprocessed on backend.
                $.cookie('login_redirect', this.options.url.checkout);

                if (this.options.url.isRedirectRequired) {
                    element.prop('disabled', true);
                    location.href = this.options.url.loginUrl;
                } else {

                return false;
            element.prop('disabled', true);
            location.href = this.options.url.checkout;
        }, this);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.