0

I need to override or extend Magento's proceed-to-checkout.js file in my module. app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js

In my modules requirejs-config.js I have tried using a mixin and also replacing the mapping with both...

var config = {
    'config': {
        'mixins': {
            'Magento_Checkout/js/proceed-to-checkout': {
                'Mynamespace_Checkout/js/view/proceed-to-checkout-mixin': true
            }
        }
    }
};

AND

var config = {
    map: {
        '*': {
            proceedToCheckout: 'Mynamespace_Checkout/js/proceed-to-checkout'
        }
    }
};

Neither work and I'm unsure how I should write the mixin as Magento's original proceed-to-checkout.js file simply returns an anonymous function with a jQuery click event listener.

Any idea how I can get this to work in a module?

1

Try following way:

app/code/SR/MagentoCommunity/view/frontend/requirejs-config.js

var config = {
    map: {
        '*': {
            "Magento_Checkout/js/proceed-to-checkout": 'SR_MagentoCommunity/js/proceed-to-checkout'
        }
    }
};

app/code/SR/MagentoCommunity/view/frontend/web/js/proceed-to-checkout.js

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

    return function (config, element) {
        console.log('new');
        $(element).click(function (event) {
            var cart = customerData.get('cart'),
                customer = customerData.get('customer');

            event.preventDefault();

            if (!customer().firstname && cart().isGuestCheckoutAllowed === false) {
                authenticationPopup.showModal();

                return false;
            }
            $(element).attr('disabled', true);
            location.href = config.checkoutUrl;
        });

    };
});

Clear static content if you are not in developer mode.

| improve this answer | |
  • Perfect, thanks! – Holly May 30 '19 at 12:49

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.