Shopware 6为自定义实体创建数据库条目

时间:2019-10-24 10:18:54

标签: plugins shopware

我正在尝试按照BundleExample&Storefinder的方式为Shopware6构建一个插件,并且一直坚持为我的实体创建相应的条目。我向管理员添加了一个模块,该模块包含3个组件:列表,详细信息和创建 分别路由到[供应商名称]。[插件名称] .list / .detail / .create。

通过custom \ plugins [plugin-name] \ src \ Resources \ administration \ module [vendor-name]-[plugin-name] \ index.js

    routes:{
        list:{
            component: '[vendor-name]-[plugin-name]-list',
            path: 'list'
        },
        detail:{
            component: '[vendor-name]-[plugin-name]-detail',
            path: 'detail/:id',
            meta:{
                parentPath: '[vendor-name].[plugin-name].list'
            }
        },
        create:{
            component: '[vendor-name]-[plugin-name]-create',
            path: 'create',
            meta:{
                parentPath: '[vendor-name].[plugin-name].list'
            }
        }
当数据库中没有条目时,将按预期显示

/ list,这意味着只有智能栏可见。 / detail无法工作,因为没有实体,因此没有id。 / create应该通过

生成一个实例
created(){
   this.repository = this.repositoryFactory.create('[vendor-name]_[plugin-name]');
   this.repository.create(this.context);
}

但是什么也没发生。

我确定我在某个地方忽略了一个基本步骤,并且希望我能获得如何实际生成条目的任何指示。 如果需要进一步的代码来阐明问题,我将很乐意提供。

1 个答案:

答案 0 :(得分:1)

this.repository.create(this.context);行将在客户端创建您的自定义实体的实体对象。 要保存该实体,您必须调用this.repository.save(entity, this.context);。 然后,您应该能够在浏览器的开发控制台中看到正在发送到服务器的请求。

有关更多信息,请查看docs

请记住,this.repository.create(this.context);创建了一个空的虚拟实体,因此您至少需要设置自定义实体的所有必填字段。