How to access older version of order via API

I am using the endpoint /api/search/order to gain data for an export. As i need older versions of a specific order, i am trying to search with the versionId (which i know from the documents endpoint and which i also find in the database for the specific order).
Using the following filter I get zero results.

{
„filter“: [
{
„type“: „equals“,
„field“: „versionId“,
„value“: „0190737f9592733b9322b9e3e0742f0a“
},
{
„type“: „equals“,
„field“: „id“,
„value“: „019072b4aabb7015b45701e75c8cac8c“
}
]
}

Is there any point where I have to activate the API-output of versioned entities or do i have to add futher data to the request?

this is really a „hard one“ I can remember I was looking for hours on this. But at the end it is easy:

The solutions uses the context. So use the context you already have and use the method createWithVersionId

$contextHistorical = $contextLiveVersion->createWithVersionId($versionId);

now you can use $contextHistorical with the orderId to search and fetch the data

$order = $this->fetchOrder($orderId, $context);

here is the fetchOrder Method:

private function fetchOrder(string $orderId, Context $context)
    {
        $criteria = (new Criteria([$orderId]))
            ->addAssociation('lineItems')
            ->addAssociation('transactions')
            ->addAssociation('deliveries.shippingMethod')
            ->addAssociation('deliveries.positions.orderLineItem')
            ->addAssociation('deliveries.shippingOrderAddress.country')
            ->addAssociation('deliveries.shippingOrderAddress.countryState');

        return $this->orderRepository
            ->search($criteria, $context)
            ->get($orderId);
    }

best

Carsten

1 „Gefällt mir“

Dieses Thema wurde automatisch 30 Tage nach der letzten Antwort geschlossen. Es sind keine neuen Antworten mehr erlaubt.