简体   繁体   中英

How to override third party module Js widget in custom module in magento 2

Here i'm trying to extend Amasty js widget in my module using mixin. I have created requirejs-config.js file like below

var config = {
    config: {
        mixins: {
            'amShopbyAjax': {
                'vendor_CustomCatalog/js/amasty/amShopbyAjax-override': true
            }
        }
    }
};

I have created js file like below

define([
    "jquery",
    "jquery-ui-modules/widget"
], function ($) {
    'use strict';
    var amShopbyWidgetMixin = {
        selectors: {
            category_products_wrapper: '#amasty-shopby-category-product-list',
        },

        reloadHtml: function (data) {
            console.log("Sdfsdfsdf");
            return this._super();
        },
        callAjax: function (clearUrl, data, pushState, cacheKey, isSorting) {
            console.log("sdnjkasndnsadj");
            return this._super();
        }
    };
    return function (targetWidget) {
        $.widget('custom.amShopbyAjax', targetWidget, amShopbyWidgetMixin);
        return $.custom.amShopbyAjax;
    };
});

After that I ran sudo bin/magento setup:static-content:deploy -f and clear cache then I am getting "Uncaught TypeError: base is not a constructor" error

Think that you should change custom.amShopbyAjax to mage.amShopbyAjax

return function (targetWidget) {
    $.widget('mage.amShopbyAjax', targetWidget, amShopbyWidgetMixin);
    return $.mage.amShopbyAjax;
};

The widget alias should be like for the target widget and the widget by parent alias should be returned

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM