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

标签 shopware

仅供引用:产品是我的 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/

相关文章:

javascript - 商店用品 6 : Reload a route after saving function using the Administration

Shopware6 将选项从 twig 模板加载到 Js 插件

plugins - 如何扩展Shopware客户

shopware - 如何在 shopware6 中创建的订单上将订单状态从打开更改为报价?

node.js - 找不到 vue-template-compiler@2.6.14 的匹配版本 | Shopware 6.5 更新后的 Node 问题

php - 将 smarty 中的 url 连接到带有字符串的给定链接

Shopware 6 购物车 API

apache2 www到非www重定向不起作用

html - 带有 HTML 和 CSS 的代码元素破坏了我在 Shopware 中的购物世界