0

i'm trying to create custom popup modal when click on "Go to checkout" button from Minicart.

i have write this code to open custom modal if the guest checkout is disabled, and redirect the customer to checkout if the customer is logged in.

this is my minicart mixin

define([
    'jquery',
    'Magento_Customer/js/model/authentication-popup',
    'Magento_Customer/js/customer-data'
], function ($, authenticationPopup, customerData) {
    'use strict';
    
    return function (Component) {
        return Component.extend({

            /**
             * @override
             */
            getCartParam: function (name) {
                var self = this;

               if (name === 'possible_onepage_checkout') {
                    $('#top-cart-btn-checkout').click(function (event) {
                        event.preventDefault();
                        var customer = customerData.get('customer');
                        if (!customer().firstname) {
                            $('.mobile-sendotp-popup').modal('openModal');
                            console.log("hello guest open poup");
                            return false;
                        } else {
                            console.log("hello customer checkout");
                            location.href = window.checkout.checkoutUrl;
                        }
                    });
               }
                return this._super(name);
            },
        });
    }
});

it's working fine when i'm browsing as guest, but when trying to go to checkout after logged in, then the button is not clickable at all and print this in log

                    hello guest open poup

so after lot of investigation i see that it doesn't read customerData at all!

kindly advise.

2
  • I've tested your code, and it works as expected for both guest and logged in customer. Let's check the Console tab and share related logs in your post.
    – Tu Van
    Oct 30, 2022 at 19:38
  • @TuVan thanks, i've debugging the problem, and i discover that the issue in Browser Local Storage. it doesn't clear the local storage (customer) after logout? any advise?
    – JosefBy
    Nov 1, 2022 at 10:34

0

Your Answer

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

Browse other questions tagged or ask your own question.