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.

0

I would suggest, try to implement your code as per the reference site.

Call default Magento 2 authentication popup from a custom module

5
  • Hi, @nits thanks for commenting. but I already tried this solution its does open the popup..but not on the first click...It requires a complete page reload to respond on click.
    – Nit
    Sep 14 '20 at 6:14
  • 1
    @Nit, first of all, every popup requires to load the page and this popup is completely dependent on the section to be loaded, then after it will open the popup. Or there is another solution like load login field in the HTML and hide/show this HTML in the popup. This will work for you.
    – Nits
    Sep 14 '20 at 6:45
  • @Nit Please try this extension. github.com/manishjoy/customer-ajax-login Hope this will help.
    – Nits
    Sep 14 '20 at 6:46
  • I will try both of your suggestion and let you know if I successful. please stay connected
    – Nit
    Sep 14 '20 at 6:59
  • Sure, you can email me if you need my help. nitish250788@gmail.com
    – Nits
    Sep 14 '20 at 9:20
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
    Sep 15 '20 at 10:39
  • did you checked that the sidebar.js file change was reflected in static content.? Sep 19 '20 at 8:26
  • yes..i removed cache and even browser cache..but no luck.
    – Nit
    Sep 21 '20 at 6:51
  • run setup upgrade and content deploy commands and then check. Sep 21 '20 at 7:35

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.