[英]How to create a backend module with a custom listing in shopware 6?
[英]Shopware 6 create DB entry for custom entity
我正在嘗試按照 BundleExample & Storefinder 為 Shopware6 構建一個插件,並且一直堅持為我的實體創建相應的條目。 我向管理員添加了一個模塊,該模塊具有 3 個組件:列表、詳細信息和創建,分別路由到 [vendor-name].[plugin-name].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);
}
但什么都沒有發生。
我確定我在某處忽略了一個基本步驟,並且會感謝任何關於我如何讓它實際生成條目的指針。 如果進一步的代碼有助於澄清問題,我將很樂意提供。
this.repository.create(this.context);
行將在客戶端創建您的自定義實體的實體 object。 要保存該實體,您必須調用this.repository.save(entity, this.context);
. 然后您應該能夠在瀏覽器的開發控制台中看到正在發送到服務器的請求。
有關更多信息,請查看文檔。
請記住this.repository.create(this.context);
創建一個空的虛擬實體,因此您至少需要設置自定義實體的所有必填字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.