在新选项卡中显示自定义产品关联数据

Display custom product association data in a new tab

我写了一个扩展来将数据添加到 Shopware 6 中的 ProductEntity 并使用了以下教程: https://developer.shopware.com/docs/guides/plugins/plugins/framework/data-handling/add-complex-data-to-existing-entities

我还使用了另一个教程 (https://developer.shopware.com/docs/guides/plugins/plugins/administration/add-new-tab) 将新选项卡添加到产品详细信息视图。到目前为止一切正常。

在产品详细信息视图中,我在自定义选项卡中添加了一个文本字段。但我的问题是:如何将我的数据放入视图中?我想在加载详细信息视图时将我的新关联添加到产品中。因此,我尝试按如下方式覆盖 Shopware 中的组件:

Shopware.Component.override('sw-product-detail', {
    template,

    mounted() {
        const criteria = this.productCriteria;
        criteria.addAssociation('myNewAssociation');
        this.productCriteria =criteria;
    },
});

这不起作用,因为 productCriteria 没有 setter(可以在此处找到原始组件:https://github.com/shopware/platform/blob/6.4.1.0/src/Administration/Resources/app/administration/src/module/sw-product/page/sw-product-detail/index.js

有谁知道如何在 Shopware 6 中向 vue.js 中的现有关联添加自定义关联?将自定义关联注入产品详细信息视图以便我可以在我的新自定义选项卡中使用来自该视图的数据的正确方法是什么?文档总是在变得有趣时停止...

我建议重写 productCriteria 方法并调用父级不需要完全复制现有代码,如下所示:


Shopware.Component.override('sw-product-detail', {
    template,

    computed: {
        productCriteria() {
            const criteria = this.$super('productCriteria');
            criteria.addAssociation('myNewAssociation');
            return criteria;
       },
    },
});

如果有效请告诉我。

我相信你也不需要在覆盖中提到template(我上次这样做时,模板显示了两次)

编辑:模板一切正常。