Skip to content

Commit

Permalink
Add initSimpleOrder method to hit fast API init endpoint (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolenorman authored May 17, 2024
1 parent fad990a commit 9ddb8eb
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Model/Order/InitOrderFromQuote.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
class InitOrderFromQuote
{
private const INIT_URL = '/checkout/orders/{{shopId}}/init';
private const INIT_SIMPLE_ORDER_URL = '/checkout_sidekick/{{shopId}}/order';
private const FLOW_ID = 'Bold-Magento2';

/**
Expand Down Expand Up @@ -115,6 +116,30 @@ public function init(CartInterface $quote, string $flowId = self::FLOW_ID): arra
return $orderData;
}

/**
* Initialize a simple order on Bold side.
* @param CartInterface $quote
* @param string $flowId
* @return array
* @throws LocalizedException
*/
public function initSimpleOrder(CartInterface $quote, string $flowId = self::FLOW_ID): array
{
$websiteId = (int)$quote->getStore()->getWebsiteId();
$body = [
'flow_id' => $flowId,
'order_type' => 'simple_order',
'cart_id' => $quote->getId(),
];

$orderData = $this->client->post($websiteId, self::INIT_SIMPLE_ORDER_URL, $body)->getBody();
$publicOrderId = $orderData['data']['public_order_id'] ?? null;
if (!$publicOrderId) {
throw new LocalizedException(__('Cannot initialize order for quote with id = "%1"', $quote->getId()));
}
return $orderData;
}

/**
* Retrieve customer addresses countries.
*
Expand Down

0 comments on commit 9ddb8eb

Please sign in to comment.