【问题标题】:How to Update Order custom field in Shopware 6 during order process?如何在订单过程中更新 Shopware 6 中的订单自定义字段?
【发布时间】:2021-06-01 00:13:08
【问题描述】:

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

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

【问题讨论】:

  • 我看不到您添加了日期字段。请更新您的代码示例。为什么要在结帐时使用日期选择器?应该与订单相关还是与购物篮相关?

标签: symfony data-access-layer shopware dbal


【解决方案1】:

在订购过程中,您究竟想在哪里添加该数据?

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

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

?>

【讨论】:

  • 如果我在结帐/确认中有输入字段,如何在 addCustomFieldsToConvertedCart 函数中传递这些字段的值。它们可以通过事件变量获得吗?
猜你喜欢
  • 2020-10-30
  • 2023-03-15
  • 2016-07-25
  • 1970-01-01
  • 2020-04-25
  • 1970-01-01
  • 2021-11-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多