I am having form with input box, we have to check if entered number is order Id or increment Id.
2 Answers
You can load order programmatically by given value. First load by ID and then load by increment ID. You can predict in either condition. For example if order object is successfully loaded by ID (given value) then it is order ID and if order object is successfully loaded by increment ID (given value) then it is increment ID.
I use the following code:
$salesOrderCollection = $this->salesOrderCollectionFactory->create();
$orderCollection = $salesOrderCollection
->addFieldToSelect('*')
->addFieldToFilter('customer_id', ['null' => true])
->addFieldToFilter('entity_id', $orderId)
->load();
if (!$orderCollection->count()) {
$orderCollection = $salesOrderCollection
->addFieldToSelect('*')
->addFieldToFilter('customer_id', ['null' => true])
->addFieldToFilter('increment_id', $orderId)
->load();
}
$order = $orderCollection->getFirstItem();
return $order;
This is working perfectly.