diff --git a/Api/Order/GetOrderFromQuoteIdInterface.php b/Api/Order/GetOrderFromQuoteIdInterface.php new file mode 100644 index 0000000..652eb9b --- /dev/null +++ b/Api/Order/GetOrderFromQuoteIdInterface.php @@ -0,0 +1,17 @@ +orderRepository = $orderRepository; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + } + + /** + * @param int $quoteId + * @return OrderInterface + * @throws LocalizedException + */ + public function getOrder(int $quoteId): OrderInterface + { + $searchCriteria = $this->searchCriteriaBuilder + ->addFilter(OrderInterface::QUOTE_ID, $quoteId) + ->create(); + + $ordersList = $this->orderRepository->getList($searchCriteria); + + if ($ordersList->getTotalCount() === 0) { + throw new LocalizedException(__('No order found with quote id="%1"', $quoteId)); + } + + $orders = $ordersList->getItems(); + return reset($orders); + } +} diff --git a/etc/di.xml b/etc/di.xml index 1e5ae15..20abd28 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -33,6 +33,7 @@ + diff --git a/etc/webapi.xml b/etc/webapi.xml index 8052857..ef23c07 100644 --- a/etc/webapi.xml +++ b/etc/webapi.xml @@ -42,6 +42,12 @@ + + + + + +