【问题标题】:Magento 2 - mixin for mixinMagento 2 - mixin for mixin
【发布时间】:2020-01-17 10:41:16
【问题描述】:

如何为已经存在的mixin 构建mixin?有可能吗?

我需要覆盖 Vendor_Module:js/checkout-mixin 中的一个函数,该函数已经是 mixinMagento_Checkout:js/something

我尝试在 requirejs-config.js 中设置它,就像我通常在定义 mixin 时所做的那样,但它不起作用。

不能直接为Magento_Checkout:js/something 设置新的mixin

谢谢

【问题讨论】:

  • 我也试过了,但我也失败了。我认为混入mixin是不可能的。

标签: magento2


【解决方案1】:

抱歉,如果您想第二次混入已经混入的文件,这是可能的。

这里是magento本身提供的面包屑js的最佳示例

只需将此代码放入您的 requirejs-config.js 中

var config = {
    config: {
        mixins: {
            'Magento_Catalog/js/product/breadcrumbs': {
                'Vendor_ModuleName/js/breadcrumbs-mixin': true
            }
        }
    }
};

并将这段代码放在你自己的 js 目录下的 vendor_company 模块中

define([
    'jquery',
    'Magento_Catalog/js/product/breadcrumbs',
    'jquery/ui'
], function ($) {
    'use strict';
    return function (widget) {
        $.widget('mage.breadcrumbs', widget, {
            /**
             * {@inheritdoc}
             */
            _getCategoryCrumb: function (menuItem) {
                //do some custom stuff
                return this._super(menuItem);
            },
        });
        return $.mage.breadcrumbs;
    };
});

你可以把你的其他方法像

_getCategoryCrumb: function (menuItem) {
                //do some custom stuff
                return this._super(menuItem);
            },

【讨论】:

    猜你喜欢
    • 2019-03-02
    • 1970-01-01
    • 2017-05-05
    • 2013-07-06
    • 2014-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多