I have created custom extension and how to fire custom ajax before add to cart ajax fire in product detail page from my custom module. I don't want to override js in theme level. please suggest any solution

  • I've given answer, if any doubts please comment below. Thanks – Prathap Gunasekaran Feb 19 '19 at 8:54

In your custom module (suppose my custom module is Anshu_Custom), add requirejs-config.js under Anshu/Custom/view/frontend

var config = {
    config: {
        mixins: {
            'Magento_Catalog/js/catalog-add-to-cart': {
                'Anshu_Custom/js/add-to-cart-mixin': true

Now create your mixin js file add-to-cart-mixin.js under Anshu/Custom/view/frontend/web/js

define(['jquery'], function($){
    'use strict';

    return function(catalogAddToCart){ // this function receives the return value of the mixin target
        $.widget('mage.catalogAddToCart', catalogAddToCart, {
            submitForm: function(form) {
        // your custom code
                return this._super(form);
        return catalogAddToCart; // always mixins has to return a function

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.