0

I want to check if a user is logged in before proceeding to checkout. On the basis of customer login condition, i want to show the login popup if not login, and redirect to checkout if logged in already.

IMPORTANT: I have guest checkout enabled in the configuration. Because I want user to checkout with guest account

I am able to redirect user to login page when not logged in. But not able to use popup instead of redirecting it to login page.

to redirect user to login page, I did the following changes in my minicart.js file:

var cc = customerData.get('customer');
if(cc().firstname){
    console.log("customerData",true);
    var urls = window.checkout.checkoutUrl; 
}else{
    console.log("customerData",false);
    $( document.body ).removeClass( "logedin" );
    var urls = window.checkout.customerLoginUrl;
}

please help me find out how to use popup login instead redirecting to login page.

2

1 Answer 1

0

You can override vendor/magento/module-checkout/view/frontend/web/js/sidebar.js file in your theme and remove cart().isGuestCheckoutAllowed === false from if (!customer().firstname && cart().isGuestCheckoutAllowed === false) {} condition. So if customer is not logged in then it will open popup.

Original Code:

if (!customer().firstname && cart().isGuestCheckoutAllowed === false) {
    ...
}

After condition removal:

if (!customer().firstname) {
    ...
}

As per old condition, it checks if a customer is not logged and guest checkout is disabled and as per new condition it will check only if a customer is not logged in.

4
  • tried it already buddy..not working
    – Nit
    Commented Sep 15, 2020 at 10:39
  • did you checked that the sidebar.js file change was reflected in static content.? Commented Sep 19, 2020 at 8:26
  • yes..i removed cache and even browser cache..but no luck.
    – Nit
    Commented Sep 21, 2020 at 6:51
  • run setup upgrade and content deploy commands and then check. Commented Sep 21, 2020 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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