php - 如何在 Shopware 6 中为订单添加自定义字段?

标签 php custom-fields shopware

默认情况下,您可以将自定义字段添加到多个实体,但我在可用实体列表中看不到订单实体。

是否可以为订单添加这样一个字段,以便用户可以在发送订单之前在结账过程中填写它?

是否可以为订单和每个订单项目单独添加一个字段?

最佳答案

这是一个关于如何向订单实体添加自定义字段的示例:

$customFieldSetRepository = $this->container->get('custom_field_set.repository');
    
            $customFieldSetRepository->upsert([
                [
                    'name' => self::FIELD_NAME,
                    // 'global' => true,
                    'config' => [
                        'label' => [
                            'de-DE' => 'Name',
                            'en-GB' => 'Name'
                        ]
                    ],
                    'customFields' => [
                        [
                            'name' => 'name',
                            'type' => CustomFieldTypes::DATETIME,
                            'config' => [
                                'type' => 'date',
                                'dateType' => 'date',
                                'label' => [
                                    'de-DE' => 'Date',
                                    'en-GB' => 'Date'
                                ]
                            ]
                        ],
                        [
                            'name' => 'name',
                            'label' => "Time",
                            'type' => CustomFieldTypes::TEXT,
                            'config' => [
                                'label' => [
                                    'de-DE' => 'name',
                                    'en-GB' => 'name'
                                ]
                            ]
                        ],
                        [
                            'name' => 'name',
                            'label' => "name",
                            'type' => CustomFieldTypes::INT,
                            'config' => [
                                'label' => [
                                    'de-DE' => 'name',
                                    'en-GB' => 'name'
                                ]
                            ]
                        ]
                    ],
                    'relations' => [[
                        'entityName' => 'order'
                    ]],
                ]
            ], $context);

关于php - 如何在 Shopware 6 中为订单添加自定义字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62827406/

相关文章:

php - 在 CI 的 sql 中使 where 子句动态化

php - 如何在 mySQL 中将表名与变量值连接起来

elasticsearch - 生成 filebeat 自定义字段

progressive-web-apps - 商店软件 PWA : Disable buying Product before it is Released

mysql - Shopware Docker无法登录Docker MySQL数据库

php - 从动态 MySql 表中的第 n 行开始获取 m 行

php - 为什么我们使用 try block 来抛出异常。我们不能在没有 try block 的情况下简单地抛出并捕获它们吗?它的重要性是什么?

php - 在 WooCommerce 3 中将自定义列添加到管理产品列表

sitecore - 按显示名称对 treelistex 进行排序,每种语言的可用项目和选定项目

php - Smarty 模板 : How to change the order of blocks in child template?