My understanding is that Shopware 6 creates a new order version each time a document is created. So that an "unchangeable" order is associated with the document (invloice, credit note etc).
I am trying to load all documents within a given time frame, including some associations like orders.
The problem is that the order always seems to be loaded with the LIVE version: 0fa91ce3e96a4bc2be4bd9ce752c3425.
My Criteria:
$criteria = new Criteria();
$criteria->addFilter(new RangeFilter('config.documentDate', [
RangeFilter::GTE => $from->format('Y-m-d'),
RangeFilter::LTE => $till->format('Y-m-d')
]));
if ($salesChannelIds) {
$criteria->addFilter(new EqualsAnyFilter('salesChannelId', $salesChannelIds));
}
$criteria->addAssociation('documentType');
$criteria->addAssociation('order');
$criteria->addAssociation('order.lineItems');
$criteria->addAssociation('order.transactions');
$criteria->addAssociation('order.deliveries');
$criteria->addAssociation('order.deliveries.shippingOrderAddress.country');
$criteria->addAssociation('order.salesChannel');
$criteria->addAssociation('order.billingAddress');
$criteria->addAssociation('order.billingAddress.country');
$documents = $this->documentRepository->search($criteria, $context)->getEntities();
The Result is:
I can work around this by loading all documents first and then loading the orders one at a time and adding the versionId as a filter.
orderVersionId = $documentLiveVersion->getOrderVersionId();
$criteria->addFilter(new EqualsFilter('order.versionId', $orderVersionId))
But now I have to run hundreds of SQL statements. Is this behaviour intended? How can I load related orders in the correct version?
