Skip to content

Commit

Permalink
feat: find order by api identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
joerivanveen committed Dec 5, 2024
1 parent 28096ef commit d108e88
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Pdk/Plugin/Repository/PdkOrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,38 @@ public function get($input): PdkOrder
});
}

public function getByApiIdentifier(string $uuid): ?PdkOrder
{
/**
* Load the most recent orders to search for the apiIdentifier.
* Assuming change webhooks are fired for recent orders.
*/
$orderIds = wc_get_orders([
'limit' => 800,
'status' => ['on-hold', 'processing', 'completed'],
'orderby' => 'date',
'order' => 'DESC',
'return' => 'ids',
]);

foreach ($orderIds as $orderId) {
$order = $this->wcOrderRepository->get($orderId);
$orderData = $order->get_meta(Pdk::get('metaKeyOrderData'));
if (isset($orderData['apiIdentifier']) && $orderData['apiIdentifier'] === $uuid) {
return $this->get($orderId);
}
}

Logger::log(
'Did not find order with apiIdentifier',
[
'apiIdentifier' => $uuid,
]
);

return null;
}

/**
* @param \MyParcelNL\Pdk\App\Order\Model\PdkOrder $order
*
Expand Down

0 comments on commit d108e88

Please sign in to comment.