🧾 Magento 2 Order Processing – From Checkout to Complete
Magento 2 provides a structured way to handle orders from checkout to shipment and completion. Whether you’re automating order handling or customizing workflows, it’s key to understand how order processing works internally.
🛒 Step-by-Step Order Flow in Magento 2
- Customer places an order
- Order is saved with status
pending
- Admin/integration generates an invoice (order status becomes
processing
) - Shipment is created (optional depending on fulfillment)
- Order is marked
complete
once invoiced and shipped
📦 Load Order by Increment ID
$order = $this->orderRepository->get($orderId); // or by increment ID $order = $this->orderRepository->getList( $this->searchCriteriaBuilder ->addFilter('increment_id', '000000123') ->create() )->getFirstItem();
🧾 Create an Invoice Programmatically
if ($order->canInvoice()) { $invoice = $invoiceService->prepareInvoice($order); $invoice->register(); $invoice->save(); $transaction = $transactionFactory->create() ->addObject($invoice) ->addObject($invoice->getOrder()); $transaction->save(); }
🚚 Create a Shipment Programmatically
if ($order->canShip()) { $shipment = $shipmentFactory->create($order, $order->getAllItems()); $shipment->register(); $shipment->getOrder()->setIsInProcess(true); $transaction = $transactionFactory->create() ->addObject($shipment) ->addObject($shipment->getOrder()); $transaction->save(); }
❌ Cancel an Order
if ($order->canCancel()) { $order->cancel(); $order->save(); }
🔁 Full Order Lifecycle Recap
- Pending – Order placed but not invoiced
- Processing – Invoice created
- Complete – Order shipped and invoiced
- Canceled – Order canceled manually or automatically
This flow can be customized via plugins, observers, or service contracts to integrate with ERP systems, shipping APIs, or CRMs.
Magento 2’s order processing is powerful and modular – once you understand the lifecycle, automation becomes easy!