Magento – How to get a quote id after an order is made

checkoutdatabasequote

Okay the question is how to get a quote id after an order is made.. and I know what people are going to say – why?

Well I have some custom details being inserted into a custom table at checkout (via a module of course) and am tracking the session with the quote id so that data can be later edited by the user (upon reviewing the order and in the 'my account' section).

So imagine the table has 5 columns: 'entry_id', 'quote_id', 'order_id', 'custom_data', 'created_at'.

All of the columns (except order id of course) are filled in before final checkout (order placed) but the quote is no longer accessible after this so I cannot add the order id to the correct entry and therefore lose the ability to edit the details. This post – Is it possible to get the QuoteId that was used once an OrderId has been created – didn't work – perhaps an older version of magento and it's methods seem loose. There must be a standard technique for this that is full-proof.

Suggestions as to an alternative way to go about what I'm doing are also welcome. Thanks

Best Answer

Sure, the quote_id is saved with the order, so you can just:

$order->getQuoteId()

And the method should work too, maybe you couldn't load the order...

To get the order, you can hook in one of the events after the order creation:

  • checkout_onepage_controller_success_action
  • checkout_type_onepage_save_order_after
  • checkout_submit_all_after

If you only need the order ID, you can just use checkout_type_onepage_save_order_after and save the ID to the database.

Related Topic