1

I am getting order details through sales/order by using load(order_id). But load does not give the data, but loadIncrementById() returns the order data.

What is the difference between these load() and loadIncrementById()?and which situation these are used?

Is all model can be extracted by using these methods?

  • are you using the same parameter for load and loadByIncrementId? – Marius Dec 8 '14 at 12:27
  • Yes @Marius I used order_id. – Manikandan Arunachalam Dec 8 '14 at 12:29
  • Then, what Luke answered below explains it nicely. – Marius Dec 8 '14 at 12:38
4

sales_flat_orders has its primary key "entity_id". This is what you try to load when you use function load()

$order->load(12345)
select entity_id, increment_id from sales_flat_order where entity_id=12345;

vs

$order->loadByIncrementId(12345)
select entity_id, increment_id from sales_flat_order where increment_id=12345;

Most models are loaded by their primary key, and the simple load() function.

However there are a few nice little functions like this scattered about the place, another example would be Mage::getModel('customer/customer')->loadByEmail()

  • But when i log the result of both methods they are different why?. – Manikandan Arunachalam Dec 8 '14 at 12:28
  • 1
    Where are you retrieving the order_id that you want to load? It will be because entity_id in the database is not equal to increment_id in the database. Whatever is giving you the order_id that you are using, is actually returning you the orders increment_id. So when you try and do a load, you're trying to load an order by entity_id when using the increment_id. This order does not exist, which gives you different values. – Luke Rodgers Dec 8 '14 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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