微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何在订单过程中更新 Shopware 6 中的订单自定义字段?

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

$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);
    }
}

?>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。