0

I am having form with input box, we have to check if entered number is order Id or increment Id.

2 Answers 2

1

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.

0

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.

2
  • If this works for you, please accept your own answer :)
    – sv3n
    Commented Jun 9, 2017 at 13:31
  • Yes I find the solution and updated here. Commented Jun 9, 2017 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.