I am currently facing a strange behaviour on shopware 6.
What I need is to get order's documents informations when the order is refunded (invoice number & creditNote number).
Here is how I am getting the documentEntity
in the orderRepository
:
$criteria = new Criteria([$orderId]);
$criteria->addAssociation('lineItems');
$criteria->addAssociation('documents');
$orderObject = $this->orderRepository->search($criteria, $context);
$documents = $orderObject->first()->getDocuments();
Normal behaviour
When the order state is set to "refunded_partially", $documents
perfectly contains what it should.
The problem
When the order state is set to "refunded", $documents
is empty and I have no errors in logs.
Maybe I overlooked but I saw no differences between the dump I made on $orderObject
when it's "refunded" and when it's "refunded_partially".
Does someone have a clue on how to manage this correctly?
AS this one is pretty tricky to do, I recommand you to use a specific event to work with documents. The event is triggered when a document is created for an order (invoice, credit note, etc.) Example here