Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endpoint to get order from quote id #305

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Api/Order/GetOrderFromQuoteIdInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Bold\Checkout\Api\Order;

use Magento\Sales\Api\Data\OrderInterface;

/**
* Gets the order from the quote id.
*/
interface GetOrderFromQuoteIdInterface
{
/**
* @param int $quoteId
* @return \Magento\Sales\Api\Data\OrderInterface
*/
public function getOrder(int $quoteId): OrderInterface;
}
52 changes: 52 additions & 0 deletions Model/Order/GetOrderFromQuoteId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);

namespace Bold\Checkout\Model\Order;

use Bold\Checkout\Api\Order\GetOrderFromQuoteIdInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderRepositoryInterface;

class GetOrderFromQuoteId implements GetOrderFromQuoteIdInterface
{
/**
* @var OrderRepositoryInterface
*/
private $orderRepository;

/**
* @var SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;

public function __construct(
OrderRepositoryInterface $orderRepository,
SearchCriteriaBuilder $searchCriteriaBuilder
) {
$this->orderRepository = $orderRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
}

/**
* @param int $quoteId
* @return OrderInterface
* @throws LocalizedException
*/
public function getOrder(int $quoteId): OrderInterface
{
$searchCriteria = $this->searchCriteriaBuilder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to confirm with a Magento expert if quote id's are long lived. I thought I had heard something in the past that quote id's expire or can be cleared out by the merchant. If so, this may result in this endpoint being a new failure point for Bold.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calin is correct, to the best of my knowledge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the change in approach for the ticket this was related to it looks like this endpoint won't be needed. That on top of it sounding like this isn't a stable approach anyway I'll be closing this once the PR in the other project has been merged. Thank you both!

->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);
}
}
1 change: 1 addition & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<preference for="Bold\Checkout\Api\Data\ModuleVersion\ResultInterface" type="Bold\Checkout\Model\Data\ModuleVersion\Result"/>
<preference for="Bold\Checkout\Api\Data\ModuleVersion\ModuleVersionInterface" type="Bold\Checkout\Model\Data\ModuleVersion\ModuleVersion"/>
<preference for="Bold\Checkout\Model\Order\CompleteOrderInterface" type="Bold\Checkout\Model\Order\CompleteOrderPool"/>
<preference for="Bold\Checkout\Api\Order\GetOrderFromQuoteIdInterface" type="Bold\Checkout\Model\Order\GetOrderFromQuoteId"/>
<type name="Bold\Checkout\Model\Order\CompleteOrderPool">
<arguments>
<argument name="pool" xsi:type="array">
Expand Down
6 changes: 6 additions & 0 deletions etc/webapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
<resource ref="Magento_Sales::create"/>
</resources>
</route>
<route method="GET" url="/V1/orders/quote/:quoteId">
<service class="Bold\Checkout\Api\Order\GetOrderFromQuoteIdInterface" method="getOrder"/>
<resources>
<resource ref="Magento_Cart::manage"/>
</resources>
</route>
<route method="GET" url="/V1/orders/:publicOrderId/quote/:quoteMaskId/authorizeAndPlace">
<service class="Bold\Checkout\Api\PlaceOrderInterface" method="authorizeAndPlace"/>
<resources>
Expand Down