I've found that there are two different properties of the order in Magento API available.
order_id and order_increment_id. For sample order they can be something like order_increment_id=100000080 and order_id=81.
The Question Is: What is the difference between them? How they are considered to be used? In the web store UI I see that my order has "Order #" = 100000080. What is order_id property for?
It can be done using Magento\Sales\Api\OrderRepositoryInterface interface, all you need to do is use getList() function to fetch order data by order increment id. That's it. You received the Order object for the var_dump in the above output.
You can fetch Last order id of order by Magento\Checkout\Model\Session Object. Call method to get last order id using below way, $orderId = $this->checkoutSession->getData('last_order_id'); $orderId is your recent order id for a store.
Entity Id (entity_id column name in table) is the primary key which is used for the table to keep unique id per row and its auto-increment so when a new row is generated/inserted automatically generate latest id.
I've been working with magento API for almost a year now and can assure you that the only ID you need to use is the order_increment_id. It is used as the main ID in the order.info call. The same is true for the invoice and shipment APIs - they also use the appropriate increment id as the main one.
The order_id, which I believe is the same as entity_id, is the primary key in the sales_order table used to join all the eav tables together. It is used internally in magento, but working with the API you needn't worry about it.
I guess order_increment_id is used for displaying to the customer, and the order_id is for internal use. People find low order ids strange, they are used to seeing 10 digits or so when looking at order ids.
What silvo has said is true and thats why there is method called getLastRealOrderId();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With