6

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

9

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.

  • ..and how are you getting $order?_g – jesus g_force Harris Jan 14 '14 at 23:47
  • updated the answer – Fabian Blechschmidt Jan 15 '14 at 7:05
  • This is the only event of those 3 that fires for me - "checkout_onepage_controller_success_action" and I can't get the order with: $order = $observer->getEvent()->getOrder();. So how can i get the order data with that event? – jesus g_force Harris Jan 15 '14 at 10:55
  • Wondering if you've tested this or had some kind of experience of retrieving the quote id after the order has been made because i did research before this and there was no clear cut apparent solution - not to say there isn't one.. – jesus g_force Harris Jan 16 '14 at 16:21
  • I did this a few times. But don't ask me, what events I used. Important is, that the $order is already saved, because the $order has only an id after the save ;-) – Fabian Blechschmidt Jan 16 '14 at 20:03
0

Try This One

$order = Mage::getModel('sales/order')->load(45);
$_totalDatas = $order->getData();
print_r($_totalDatas);

The $_TotalDatas Print the Below Atrray

Array
(
    [entity_id] => 45
    [state] => processing
    [status] => pending
    [coupon_code] => stickytest
    [protect_code] => 1036b0
    [shipping_description] => Voucher code discount
    [is_virtual] => 0
    [store_id] => 1
    [customer_id] =>
    [base_discount_amount] => -195.0000
    [base_discount_canceled] =>
    [base_discount_invoiced] =>
    [base_discount_refunded] =>
    [base_grand_total] => 0.0000
    [base_shipping_amount] => 0.0000
    [base_shipping_canceled] =>
    [base_shipping_invoiced] =>
    [base_shipping_refunded] =>
    [base_shipping_tax_amount] => 0.0000
    [base_shipping_tax_refunded] =>
    [base_subtotal] => 177.2700
    [base_subtotal_canceled] =>
    [base_subtotal_invoiced] =>
    [base_subtotal_refunded] =>
    [base_tax_amount] => 0.0000
    [base_tax_canceled] =>
    [base_tax_invoiced] =>
    [base_tax_refunded] =>
    [base_to_global_rate] => 1.0000
    [base_to_order_rate] => 1.0000
    [base_total_canceled] =>
    [base_total_invoiced] =>
    [base_total_invoiced_cost] =>
    [base_total_offline_refunded] =>
    [base_total_online_refunded] =>
    [base_total_paid] =>
    [base_total_qty_ordered] =>
    [base_total_refunded] =>
    [discount_amount] => -195.0000
    [discount_canceled] =>
    [discount_invoiced] =>
    [discount_refunded] =>
    [grand_total] => 0.0000
    [shipping_amount] => 0.0000
    [shipping_canceled] =>
    [shipping_invoiced] =>
    [shipping_refunded] =>
    [shipping_tax_amount] => 0.0000
    [shipping_tax_refunded] =>
    [store_to_base_rate] => 1.0000
    [store_to_order_rate] => 1.0000
    [subtotal] => 177.2700
    [subtotal_canceled] =>
    [subtotal_invoiced] =>
    [subtotal_refunded] =>
    [tax_amount] => 0.0000
    [tax_canceled] =>
    [tax_invoiced] =>
    [tax_refunded] =>
    [total_canceled] =>
    [total_invoiced] =>
    [total_offline_refunded] =>
    [total_online_refunded] =>
    [total_paid] =>
    [total_qty_ordered] => 1.0000
    [total_refunded] =>
    [can_ship_partially] =>
    [can_ship_partially_item] =>
    [customer_is_guest] => 1
    [customer_note_notify] => 1
    [billing_address_id] => 89
    [customer_group_id] => 0
    [edit_increment] =>
    [email_sent] => 1
    [forced_shipment_with_invoice] =>
    [gift_message_id] =>
    [payment_auth_expiration] =>
    [paypal_ipn_customer_notified] =>
    [quote_address_id] =>
    [quote_id] => 215
    [shipping_address_id] => 90
    [adjustment_negative] =>
    [adjustment_positive] =>
    [base_adjustment_negative] =>
    [base_adjustment_positive] =>
    [base_shipping_discount_amount] => 0.0000
    [base_subtotal_incl_tax] => 195.0000
    [base_total_due] =>
    [payment_authorization_amount] =>
    [shipping_discount_amount] => 0.0000
    [subtotal_incl_tax] => 195.0000
    [total_due] =>
    [weight] => 1.0000
    [customer_dob] =>
    [increment_id] => 100000034
    [applied_rule_ids] => 4
    [base_currency_code] => AUD
    [customer_email] => someone@somewhere.com
    [customer_firstname] => billing[firstname]
    [customer_lastname] => billing[lastname]
    [customer_middlename] =>
    [customer_prefix] =>
    [customer_suffix] =>
    [customer_taxvat] =>
    [discount_description] => stickytest
    [ext_customer_id] =>
    [ext_order_id] =>
    [global_currency_code] => AUD
    [hold_before_state] =>
    [hold_before_status] =>
    [order_currency_code] => AUD
    [original_increment_id] =>
    [relation_child_id] =>
    [relation_child_real_id] =>
    [relation_parent_id] =>
    [relation_parent_real_id] =>
    [remote_ip] => 192.168.0.18
    [shipping_method] => matrixrate_matrixrate_free
    [store_currency_code] => AUD
    [store_name] => Main Website, Main Store,English
    [x_forwarded_for] =>
    [customer_note] =>
    [created_at] => 2012-11-19 10:53:11
    [updated_at] => 2012-11-19 10:53:12
    [total_item_count] => 1
    [customer_gender] =>
    [base_custbalance_amount] =>
    [currency_base_id] =>
    [currency_code] =>
    [currency_rate] =>
    [custbalance_amount] =>
    [is_hold] =>
    [is_multi_payment] =>
    [real_order_id] =>
    [tax_percent] =>
    [tracking_numbers] =>
    [hidden_tax_amount] => 17.7300
    [base_hidden_tax_amount] => 17.7300
    [shipping_hidden_tax_amount] => 0.0000
    [base_shipping_hidden_tax_amnt] => 0.0000
    [hidden_tax_invoiced] =>
    [base_hidden_tax_invoiced] =>
    [hidden_tax_refunded] =>
    [base_hidden_tax_refunded] =>
    [shipping_incl_tax] => 0.0000
    [base_shipping_incl_tax] => 0.0000
    [onestepcheckout_customercomment] => onestepcheckout_comments
    [onestepcheckout_customerfeedback] => Google
    [payment_authorization_expiration] =>
    [forced_do_shipment_with_invoice] =>
    [base_shipping_hidden_tax_amount] => 0.0000
)

You use Any value of from this :)

  • This method: $order = Mage::getModel('sales/order')->load(45); assumes you know the order id. It must be the current order which seems to be the crux of all this_ – jesus g_force Harris Jan 15 '14 at 10:59
  • If you want all order and get collection then use getCollection() rather then load – Keyul Shah Jan 15 '14 at 11:09
  • That will load all orders - I am looking for the quote id of the current order in the session_ – jesus g_force Harris Jan 15 '14 at 14:07
  • @jesusg_forceHarris try $cart=Mage::getSingleton('checkout/cart');$cart->init();$quote=$cart->getQuote();$quote->getId(); it returns the current quote on the session, it may change after the order is placed, depending on how the order is made, we use a custom order creation script based on Magento 1.3.2, so I can't say for certain. – user3338098 May 12 '16 at 14:25
0
Mage::getSingleton('checkout/session')->getLastOrderId() 
//this gives you the increment ID

or

Mage::getSingleton('checkout/session')->getLastRealOrderId() 
// this gives you the entity ID of the order in the database.
0

Here I am sharing the code Magento2 How to get the quote_id in checkout_onepage_controller_success_action event.

i) Firstly you have to create events.xml

 <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="cart_reminder_save_after">
        <observer name="checkout_onepage_controller_success_action" instance="Namespace\Modulename\Observer\GetQuoteId" />
    </event>
</config>

ii) Second step you have to create GetQuoteId.php file inside Observer folder

    <?php
    namespace Namespace\Modulename\Observer;

    class GetQuoteId implements \Magento\Framework\Event\ObserverInterface {

         private $logger;

            /**
         * Order Model
         *
         * @var \Magento\Sales\Model\Order $order
         */
        protected $order;

        public function __construct(
                \Magento\Sales\Model\Order $order,
                \Psr\Log\LoggerInterface $logger
            )
            {
                $this->order = $order;
                $this->logger = $logger;
            }

            public function execute(\Magento\Framework\Event\Observer $observer){
                $orderId = $observer->getEvent()->getOrderIds();
                $order = $this->order->load($orderId);

                echo $QuoteId = $order->getQuoteId(); /*Quote Id*/
                die("test it..");

                }
}


    ?>

Please let me know if you face any issue.

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.