symfony - 如何在订单过程中更新 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);
}
}
?>
推荐阅读
- excel - Excel:从列中的下一个条目中减去一个值
- c++ - 为什么 make_tie 不是一个东西?
- java - 无法卸载java
- java - @Transactional 两个事务管理器,一个事务
- r - 需要帮助改进 R 中的正则表达式代码
- autodesk-forge - 使用 ViewingApplication 初始化没有工具栏的查看器
- firebase - 用于运行 Google Cloud Platform 服务的任何服务器是否使用卡巴斯基产品?
- excel - 将具有零值的连续月份分类到存储桶中
- python - 如何安排作业(Django、Python)
- bioinformatics - RSeQC 与 multiQC 和 snakemake