将Shopware 6标签附加到属性值

huangapple go评论92阅读模式
英文:

Attach Shopware 6 tags to Property values

问题

有人能否就如何将Shopware 6的标签附加到属性(仅一个值)上提供建议?

是否有一种方法可以重用某些组件?我认为标签是使用数据关联完成的。

--

我已经设置好了,但现在我遇到了这个错误(在单击后端管理选项列表中的属性选项详细信息模态框时无法打开):

  1. app.js?16886789168584353:2 在当前模块中捕获到了一个错误:ReferenceError: option未定义

当我删除选择器时,它可以正常打开:

  1. <sw-entity-tag-select
  2. v-if="option"
  3. v-model="option.extensions.myTags"
  4. :label="$tc('global.sw-tag-field.title')"
  5. />

以下是js代码:

  1. Shopware.Component.override('sw-property-option-detail', {
  2. inject: [
  3. 'repositoryFactory'
  4. ],
  5. template,
  6. data: function () {
  7. return {
  8. option: undefined
  9. }
  10. },
  11. computed: {
  12. repository() {
  13. return this.repositoryFactory.create('a7filter_property_group_option_tag');
  14. },
  15. criteria() {
  16. const criteria = new Criteria();
  17. criteria.addAssociation('myTags');
  18. return criteria;
  19. },
  20. },
  21. created() {
  22. this.repository = this.repositoryFactory.create('a7filter_property_group_option_tag');
  23. this.repository.search(this.criteria, Shopware.Context.api)
  24. .then(option => {
  25. this.option = option;
  26. });
  27. }
  28. });

也许有人可以提供建议?

英文:

Can someone advice on making it possible to attach Shopware 6 tags to Property (only one) values?

Is there a way to reuse some components? I assume tags are done using data associations.

--

I have set it up, but now I get this error (while not being able to open Property option detail modal on click in a backend administration options list):

  1. app.js?16886789168584353:2 An error was captured in current module: ReferenceError: option is not defined

It opens well, when I remove the selector:

  1. &lt;sw-entity-tag-select
  2. v-if=&quot;option&quot;
  3. v-model=&quot;option.extensions.myTags&quot;
  4. :label=&quot;$tc(&#39;global.sw-tag-field.title&#39;)&quot;
  5. /&gt;

Here is the js:

  1. Shopware.Component.override(&#39;sw-property-option-detail&#39;, {
  2. inject: [
  3. &#39;repositoryFactory&#39;
  4. ],
  5. template,
  6. data: function () {
  7. return {
  8. option: undefined
  9. }
  10. },
  11. computed: {
  12. repository() {
  13. return this.repositoryFactory.create(&#39;a7filter_property_group_option_tag&#39;);
  14. },
  15. criteria() {
  16. const criteria = new Criteria();
  17. criteria.addAssociation(&#39;myTags&#39;);
  18. return criteria;
  19. },
  20. },
  21. created() {
  22. this.repository = this.repositoryFactory.create(&#39;a7filter_property_group_option_tag&#39;);
  23. this.repository.search(this.criteria, Shopware.Context.api)
  24. .then(option =&gt; {
  25. this.option = option;
  26. });
  27. }
  28. });

Maybe someone can give an advice?

答案1

得分: 3

Create a custom entity for the mapping

  1. class MyPropertyGroupOptionTagDefinition extends MappingEntityDefinition
  2. {
  3. final public const ENTITY_NAME = 'my_property_group_option_tag';
  4. public function getEntityName(): string
  5. {
  6. return self::ENTITY_NAME;
  7. }
  8. protected function defineFields(): FieldCollection
  9. {
  10. return new FieldCollection([
  11. (new FkField('option_id', 'optionId', PropertyGroupOptionDefinition::class))->addFlags(new PrimaryKey(), new Required()),
  12. (new FkField('tag_id', 'tagId', TagDefinition::class))->addFlags(new PrimaryKey(), new Required()),
  13. new ManyToOneAssociationField('option', 'option_id', PropertyGroupOptionDefinition::class, 'id', false),
  14. new ManyToOneAssociationField('tag', 'tag_id', TagDefinition::class, 'id', false),
  15. ]);
  16. }
  17. }

Create an EntityExtension

  1. class PropertyGroupOptionExtension extends EntityExtension
  2. {
  3. public function extendFields(FieldCollection $collection): void
  4. {
  5. $collection->add(
  6. new ManyToManyAssociationField('myTags', TagDefinition::class, MyPropertyGroupOptionTagDefinition::class, 'option_id', 'tag_id'),
  7. );
  8. }
  9. public function getDefinitionClass(): string
  10. {
  11. return PropertyGroupOptionDefinition::class;
  12. }
  13. }

Add association to criteria for property_group_option where they are fetched

  1. criteria.addAssociation('myTags');

In the template of the component you can use sw-entity-tag-select for assigning tags

  1. <sw-entity-tag-select
  2. v-if="option"
  3. v-model="option.extensions.myTags"
  4. :label="$tc('global.sw-tag-field.title')"
  5. />
英文:

Create a custom entity for the mapping

  1. class MyPropertyGroupOptionTagDefinition extends MappingEntityDefinition
  2. {
  3. final public const ENTITY_NAME = &#39;my_property_group_option_tag&#39;;
  4. public function getEntityName(): string
  5. {
  6. return self::ENTITY_NAME;
  7. }
  8. protected function defineFields(): FieldCollection
  9. {
  10. return new FieldCollection([
  11. (new FkField(&#39;option_id&#39;, &#39;optionId&#39;, PropertyGroupOptionDefinition::class))-&gt;addFlags(new PrimaryKey(), new Required()),
  12. (new FkField(&#39;tag_id&#39;, &#39;tagId&#39;, TagDefinition::class))-&gt;addFlags(new PrimaryKey(), new Required()),
  13. new ManyToOneAssociationField(&#39;option&#39;, &#39;option_id&#39;, PropertyGroupOptionDefinition::class, &#39;id&#39;, false),
  14. new ManyToOneAssociationField(&#39;tag&#39;, &#39;tag_id&#39;, TagDefinition::class, &#39;id&#39;, false),
  15. ]);
  16. }
  17. }

Create an EntityExtension

  1. class PropertyGroupOptionExtension extends EntityExtension
  2. {
  3. public function extendFields(FieldCollection $collection): void
  4. {
  5. $collection-&gt;add(
  6. new ManyToManyAssociationField(&#39;myTags&#39;, TagDefinition::class, MyPropertyGroupOptionTagDefinition::class, &#39;option_id&#39;, &#39;tag_id&#39;),
  7. );
  8. }
  9. public function getDefinitionClass(): string
  10. {
  11. return PropertyGroupOptionDefinition::class;
  12. }
  13. }

Add association to criteria for property_group_option where they are fetched

  1. criteria.addAssociation(&#39;myTags&#39;);

In the template of the component you can use sw-entity-tag-select for assigning tags

  1. &lt;sw-entity-tag-select
  2. v-if=&quot;option&quot;
  3. v-model=&quot;option.extensions.myTags&quot;
  4. :label=&quot;$tc(&#39;global.sw-tag-field.title&#39;)&quot;
  5. /&gt;

huangapple
  • 本文由 发表于 2023年6月22日 01:23:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76525763.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定