gpt4 book ai didi

shopware - 如何访问 Shopware 6 中的自定义 cms 元素配置值?

转载 作者:行者123 更新时间:2023-12-04 07:42:01 39 4
gpt4 key购买 nike

仅供引用:产品是我的 cms 元素名称。

如shopware 6 guides所示,我已经创建了一个文件

DataResolver/ProductsCmsElementResolver.php

它有一个丰富的方法来帮助扩展数据。在那里我尝试访问我的自定义 cms 元素的配置:

$config = $slot->getFieldConfig();
$productListType = $config->get('products')->getValue();

然而,它始终返回在元素注册期间设置的默认值:

Shopware.Service('cmsService').registerCmsElement({
name: 'products',
label: 'das.elements.customProductsElement.label',
component: 'sw-cms-el-products',
configComponent: 'sw-cms-el-config-products',
previewComponent: 'sw-cms-el-preview-products',
defaultConfig: {
products: {
source: 'static',
value: ''
}
}
});

我完全按照以下指南中的说明进行操作:

https://developer.shopware.com/docs/guides/plugins/plugins/content/cms/add-cms-element

https://developer.shopware.com/docs/guides/plugins/plugins/content/cms/add-data-to-cms-elements#create-a-data-resolver

谁能分享一个代码示例,您可以在其中获取配置值作为变量而不是静态值?

最佳答案

我做错的是我忘记在计算方法中写入 .value:

computed: {
products() {
return this.element.config.products.value;
}
},

但是我也在商店软件源代码中发现了文档中没有提到的这样的函数调用:

methods: {
createdComponent() {
this.initElementConfig('youtube-video');
this.initElementData('youtube-video'); // this line was not present in docs
}
}

关于shopware - 如何访问 Shopware 6 中的自定义 cms 元素配置值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67412581/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com