symfony - 如何在订单处理过程中更新 Shopware 6 中的订单自定义字段?

标签 symfony data-access-layer shopware dbal

我想在结帐的订单处理过程中添加日期选择器。订单的自定义字段应该在哪一步更新?订单或其他实体的自定义字段更新是如何完成的? 我想添加官方文档中显示的字段。

$this->customFieldSetRepository->create([
    [
        'name' => 'swag_example',
        'customFields' => [
            ['name' => 'swag_example_size', 'type' => CustomFieldTypes::INT],
            ['name' => 'swag_example_color', 'type' => CustomFieldTypes::TEXT]
        ]
    ]
], $context);

最佳答案

在订购过程中您到底想在哪里添加这些数据?

一个示例是从确认到完成 -> 购物车转换为订单。 您只需为此创建一个订阅者:

<?php

class OrderProcessSubscriber implements EventSubscriberInterface
{

    public static function getSubscribedEvents()
    {
        return [
            CartConvertedEvent::class => 'addCustomFieldsToConvertedCart',
        ];
    }

    public function addCustomFieldsToConvertedCart(CartConvertedEvent $event)
    {
        $convertedCart['customFields']['my_custom_field'] =  'test';
        $event->setConvertedCart($convertedCart);
    }
}

?>

关于symfony - 如何在订单处理过程中更新 Shopware 6 中的订单自定义字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66439604/

相关文章:

javascript - Symfony 3.3 - 我应该把 CSS 和 JS 文件放在哪里?

java - 如何在 JAVA 中使用 OAuth 2.0 获取/发布资源(状态代码 415)

shopware - 如果客户使用 Shopware 6 中的 REST API 注册,则阻止发送注册电子邮件

architecture - 数据访问层应该如何构建?

unit-testing - 模拟与测试数据库?

spring - 分布式计算的独立数据访问层

shopware - 在 Shopware 6 中限制对具有上下文的文档的访问

php - $this->getRequest() 和在 Symfony 2 中将请求作为参数传递有什么区别

symfony - 为 Sonata Admin 包配置自定义模板

php - "Missing Service"在symfony中声明新的Topic时