1

I am using the event <sales_order_place_after> in my observer to perform some action. I am inserting the Order ID in my custom table. But what I observe is that it does not give me Order ID but instead Increment ID, which I am fetching using getReservedOrderId().

Now to fetch Order ID from Increment ID I can use,

$order = Mage::getModel('sales/order')->load($incrementId, 'increment_id');

but I need to insert the data at the time of order placed, instead of fetching it again.

Observer Code;

$order = $observer->getEvent()->getOrder(); //returns null

So I am using

$order = $observer->getEvent()->getOrder()->getQuote();

Which event should be used in order to get all order details after an order is placed or on order success ?

3

There are lot of event in magento order place.

I have preferred checkout_submit_all_after event which is give Order and Quote in there Observer.

This event is occur for both frontend and backend.

Example:

<global>
        <events>

                <checkout_submit_all_after>
                    <observers>
                        <awesome_example>
                            <class>yourmodel/observer</class>
                            <method>SyncWithInfusion</method>
                        </awesome_example>
                    </observers>
                </checkout_submit_all_after>
            </events>
</global>

and Observer code is

public function SyncWithInfusion(Varien_Event_Observer $observer)
    {
        $order = $observer->getEvent()->getOrder();
    //get order
    $order->getId();
        $Quote = $observer->getEvent()->getQuote();


    }

See at:custom checkout_submit_all_after observer not working

| improve this answer | |
  • When checkout_submit_all_after will be called and how about using checkout_type_onepage_save_order_after ? I want the event that is called only when order is placed successfully. – Jordan Aug 21 '14 at 4:18
1

To get the Increment Id from the order observer use:

$increment_id = $observer->getEvent()->getOrder()->getIncrementId();

To get the order id use:

$order_id = $observer->getEvent()->getOrder()->getId();
| improve this answer | |
  • You didn't mentioned the event to be used here ? – Jordan Aug 20 '14 at 12:52
  • Same as you were referring to <sales_order_place_after> – Eirik Aug 20 '14 at 12:55
0

As you figured, you cannot get the ID before the order is saved. sales_order_place_after is dispatched before the order actually gets saved to the database (right before the transaction is committed). The very first event that is triggered after the transaction is submitted is sales_model_service_quote_submit_success.

| improve this answer | |
0

In case of magento 2.*

create a events.xml for

1.sales_order_save_after

2.sales_order_save_before

  1. events.xml <?xml version="1.0" encoding="UTF-8"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd"> <event name="{event_name}"> <observer name="{class name}" instance="{namespace of class}" /> </event> </config>

  2. observer code

    use \Magento\Framework\Event\ObserverInterface;

class Orderpush implements ObserverInterface {

protected $_class_scope_config;

public function __construct(
    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
) {
    $this->_class_scope_config = $scopeConfig;
    // parent::__construct();

}
public function execute(\Magento\Framework\Event\Observer $observer)
{

$order = $observer->getOrder(); $order->getId();

} }

| improve this answer | |

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.