简体   繁体   中英

Shopware 6 create DB entry for custom entity

I am trying to build a plugin for Shopware6 along the lines of BundleExample & Storefinder and am stuck on creating the corresponding entries for my entities. I added a module to the admin which has 3 components: list, detail and create routed to [vendor-name].[plugin-name].list/.detail/.create respectively.

From 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 is displayed as expected when there are no entries in the DB, meaning only the smartbar is visible. /detail cant work because there is no id since there are no entities yet. /create should generate an instance via

created(){
   this.repository = this.repositoryFactory.create('[vendor-name]_[plugin-name]');
   this.repository.create(this.context);
}

but nothing is happening.

I'm sure I'm overlooking a basic step somewhere and would appreciate any pointers as to how i can get it to actually generate an entry. If further code would be helpfull to clarify the question I will gladly provide it.

The this.repository.create(this.context); line will create an entity object of your custom entity on the client side. To save that entity you have to call the this.repository.save(entity, this.context); . Then you should be able to see an request being send to the server in the dev console of the browser.

For more information please take look in the docs .

Keep in mind that this.repository.create(this.context); creates an empty dummy entity, so you at least need to set all the required fields of your custom entity.

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