首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过政府将数据插入Shopware 6数据库

如何通过政府将数据插入Shopware 6数据库
EN

Stack Overflow用户
提问于 2022-09-15 08:27:09
回答 1查看 120关注 0票数 1

我已经创建了一个插件,创建了一个管理路径,但是将数据插入Shopware 6数据库不起作用。下面是我的密码。在构建过程之后,它不起作用了,我做错了什么?从下面的代码中,我试图将数据'Diekedie‘插入到'product_manufacturer_translation’表的'name‘列中。

代码语言:javascript
复制
const { Component, Mixin } = Shopware;
import template from './custom-module-list.html.twig'
Component.register('custom-module-list', {
  template,

  inject: [
   'repositoryFactory'
   ],

  metaInfo() {
     return {
         title: this.$createTitle()
     };
   },

 data: function () {

   return {
       entity: undefined
   }

  },

  methods: {

   manufacturerRepository() {
       return this.repositoryFactory.create('product_manufacturer_translation');
   }
   
  },


  computed: {
   
},

created() {

   this.manufacturerRepository();

   this.entity = this.manufacturerRepository.create(Shopware.Context.api);

   this.entity.name = 'Diekedie';

   this.manufacturerRepository.save(this.entity, Shopware.Context.api);
}





 
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-15 09:44:45

要设置翻译,您可以使用相关实体的存储库,而不是翻译本身的存储库。另外,如果有一个返回创建的存储库的方法,则必须使用该返回值来创建实体:

代码语言:javascript
复制
methods: {
   manufacturerRepository() {
       return this.repositoryFactory.create('product_manufacturer');
   },
},

created() {
   const repository = this.manufacturerRepository();

   this.entity = repository.create(Shopware.Context.api);

   this.entity.name = 'Diekedie';

   repository.save(this.entity, Shopware.Context.api);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73727890

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档