0

I want to Override Magento add-to-wishlist data-action in Magento 2

i Have Created and Override Core addtowishlist Widget

in my requirejs-config.js

var config = {
    "map": {
      "*": {
        "addToWishlist":  'Magento_Wishlist/js/add-to-wishlist',
        "addToCustomWishlist": "Vendor_Module/js/add-to-wishlist"
      }
    }
};

Now in My Custom js/add-to-wishlist.js

define([
    'jquery',
    'jquery-ui-modules/widget', // use individual jQuery UI component if your widget is for frontend or base areas
     // 'jquery/ui', // use all 'jquery/ui' library if your widget is for adminhtml area
    'addToCustomWishlist' // usually widget can be found in /lib/web/mage dir
  ], function($){

    $.widget('vendor.addToCustomWishlist', $.mage.addToWishlist, {
        bindFormSubmit: function () {
            var self = this;
             alert("I am Here");

            $('[data-action="add-to-wishlist"]').on('click', function (event) {
                var element, params, form, action;

                event.stopPropagation();
                event.preventDefault();

                element = $('input[type=file]' + self.options.customOptionsInfo);
                params = $(event.currentTarget).data('post');
                form = $(element).closest('form');
                action = params.action;

                if (params.data.id) {
                    $('<input>', {
                        type: 'hidden',
                        name: 'id',
                        value: params.data.id
                    }).appendTo(form);
                }

                if (params.data.uenc) {
                    action += 'uenc/' + params.data.uenc;
                }

                $(form).attr('action', action).submit();
            });
        },
        _updateAddToWishlistButton: function (dataToAdd) {
            var self = this;
                        alert("I am Here");
            $('[data-action="add-to-wishlist"]').each(function (index, element) {
                var params = $(element).data('post');

                if (!params) {
                    params = {
                        'data': {}
                    };
                }

                params.data = $.extend({}, params.data, dataToAdd, {
                    'qty': $(self.options.qtyInfo).val()
                });
                $(element).data('post', params);
            });
        },
     });

    return $.vendor.addToCustomWishlist;
});

I did these Following Magento Documentation But not getting any Success

0

Try this, and refresh cache:

"map": {
  "*": {
    "addToWishlist": "Vendor_Module/js/add-to-wishlist"
  }
}

In fact, remove this "addToWishlist": 'Magento_Wishlist/js/add-to-wishlist' from your config variable.

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.