Skip to content

Order management API

Order management REST API

To learn how to manage orders with the REST API, see the REST API reference.

To get orders and manage them, use the Ibexa\Contracts\OrderManagement\OrderServiceInterface interface.

Get single order

Get single order by identifier

To access a single order by using its string identifier, use the OrderService::getOrderByIdentifier method:

1
2
3
4
        $orderIdentifier = '2e897b31-0d7a-46d3-ba45-4eb65fe02790';
        $order = $this->orderService->getOrderByIdentifier($orderIdentifier);

        $output->writeln(sprintf('Order %s has status %s', $orderIdentifier, $order->getStatus()));

Get single order by ID

To access a single order by using its numerical ID, use the OrderService::getOrder method:

1
2
3
4
        $orderId = 1;
        $order = $this->orderService->getOrder($orderId);

        $output->writeln(sprintf('Order %d has status %s', $orderId, $order->getStatus()));

Get multiple orders

To fetch multiple orders, use the OrderService::findOrders method. It follows the same search query pattern as other APIs:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
use Ibexa\Contracts\CoreSearch\Values\Query\Criterion\LogicalOr;
use Ibexa\Contracts\OrderManagement\Value\Order\OrderQuery;
use Ibexa\Contracts\OrderManagement\Value\Order\Query\Criterion\CompanyNameCriterion;
use Ibexa\Contracts\OrderManagement\Value\Order\Query\Criterion\CustomerNameCriterion;
use Ibexa\Contracts\OrderManagement\Value\Order\Query\Criterion\IdentifierCriterion;


// ...
        $orderCriterions = [
            new IdentifierCriterion('c328773e-8daa-4465-86d5-4d7890f3aa86'),
            new CompanyNameCriterion('IBM'),
            new CustomerNameCriterion('foo_user'),
        ];
        $orderQuery = new OrderQuery(new LogicalOr(...$orderCriterions));
        $orders = $this->orderService->findOrders($orderQuery);

        $output->writeln(sprintf('Found %d orders with provided criteria', count($orders)));

Create order

To create an order, use the OrderService::createOrder method and provide it with the Ibexa\Contracts\OrderManagement\Value\OrderCreateStruct object that contains a list of products, purchased quantities, product and total prices, as well as tax amounts.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
        $orderCreateStruct = new OrderCreateStruct(
            $user,
            $currency,
            $value,
            'local_shop',
            $items
        );

        $order = $this->orderService->createOrder($orderCreateStruct);

        $output->writeln(sprintf('Created order with identifier %s', $order->getIdentifier()));

Update order

You can update the order after it is created. You could do it to support a scenario when, for example, the order is processed manually and its status has to be changed in the system. To update order information, use the OrderService::updateOrder method:

1
2
3
4
        $orderUpdateStruct = new OrderUpdateStruct('processed');
        $this->orderService->updateOrder($order, $orderUpdateStruct);

        $output->writeln(sprintf('Changed order status to %s', $order->getStatus()));