所以我试图用我想在管理面板中定义的单位显示产品属性。我在设置中找到了“比例单位”,但 asfaik 仅适用于产品。添加附加字段似乎也不是正确的方法,因为您无法为属性定义附加字段。
一种解决方法是在标签中添加单位,但这不是一个好的解决方案。
我无法找到解决该问题的简单方法...
所以我试图用我想在管理面板中定义的单位显示产品属性。我在设置中找到了“比例单位”,但 asfaik 仅适用于产品。添加附加字段似乎也不是正确的方法,因为您无法为属性定义附加字段。
一种解决方法是在标签中添加单位,但这不是一个好的解决方案。
我无法找到解决该问题的简单方法...
可以参考现有的单位实体,将 customField 添加到属性选项中。但无论如何,您都必须编写一些代码才能在店面中显示该单元。
编辑
在属性选项上显示自定义字段的代码示例:
Component.override('sw-property-option-detail', {
template,
data() {
return {
...
customFieldSets: []
};
},
computed: {
customFieldSetRepository() {
return this.repositoryFactory.create('custom_field_set');
},
customFieldSetCriteria() {
const criteria = new Criteria(1, 100);
criteria.addFilter(Criteria.equals('relations.entityName', 'propertyOption'));
criteria
.getAssociation('customFields')
.addSorting(Criteria.sort('config.customFieldPosition', 'ASC', true));
return criteria;
},
},
methods: {
loadEntityData() {
...
this.customFieldSetRepository
.search(this.customFieldSetCriteria, Shopware.Context.api)
.then((result) => {
this.customFieldSets = result.filter((set) => set.customFields.length > 0);
});
},
}
});
<sw-card :title="$tc('sw-settings-custom-field.general.mainMenuItemGeneral')" v-if="customFieldSets.length > 0" :isLoading="isLoading">
<sw-custom-field-set-renderer v-if="currentOption" :entity="currentOption" :sets="customFieldSets" :disabled="!allowEdit">
</sw-custom-field-set-renderer>
</sw-card>
这是一个非常具体的问题。您可能可以将现有实体用于单位并在代码中创建与属性的关联。正如您已经建议的那样,最简单的解决方案仍然是在标签中添加单位。