Shopware - 在 orderRepository 中获取 documentCollection

Shopware - Getting documentCollection in orderRepository

我目前在 shopware 6 上遇到了一个奇怪的行为。

我需要的是在订单退款时获取订单的单据信息(发票号和creditNote号)。

这是我在 orderRepository 中获取 documentEntity 的方法:

$criteria = new Criteria([$orderId]);
$criteria->addAssociation('lineItems');
$criteria->addAssociation('documents');
$orderObject = $this->orderRepository->search($criteria, $context);
$documents = $orderObject->first()->getDocuments();

正常行为

当订单状态设置为“refunded_partially”时,$documents完美包含它应有的内容。

问题

当订单状态设置为“已退款”时,$documents 为空并且我在日志中没有错误。

也许我忽略了,但我发现我在 $orderObject 上“退款”时和“refunded_partially”时所做的转储之间没有区别。

有人知道如何正确管理它吗?

由于这一项非常棘手,我建议您使用特定事件来处理文档。当为订单创建文档(发票、贷方通知单等)时触发该事件