3

How to get entity_id after order is placed.

How can i get order details with entity id in Magento2 rest api ?

4
  • you wany customer entity id from order?
    – Amit Bera
    Commented Sep 17, 2018 at 6:17
  • yes, by using entity id can we get order details ? Commented Sep 17, 2018 at 6:33
  • mean entity id means Customer Id? or order id?
    – Amit Bera
    Commented Sep 17, 2018 at 6:36
  • order id and how can i get order details of specific user. Commented Sep 17, 2018 at 6:37

2 Answers 2

1

You can hook to sales_model_service_quote_submit_success event, It is execute after order is placed.

Add event to your_module/etc/frontend/events.xml

<event name="sales_model_service_quote_submit_success">
        <observer name="your_module_sales_model_service_quote_submit_success" instance="Your_Vendor\Your_Module\Observer\SalesModelServiceQuoteSubmitSuccessObserver"/>
</event>

Create observer

namespace Your_Vendor\Your_Module\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class SalesModelServiceQuoteSubmitSuccessObserver implements ObserverInterface
{

    /**
     * Fires when sales_order_place_after is dispatched
     *
     * @param Observer $observer
     */
    public function execute(Observer $observer)
    {
        //Order information
        $order = $observer->getEvent()->getOrder();
        //Quote information
        $quote = $observer->getEvent()->getQuote();

        //Get customer_id from order
        $customerId = $order->getCustomerId();

        //Or Get customer_id from quote
        $customerId = $quote->getCustomerId();
    }
}
2
  • how can i get order_id or entity_id after placing order Commented Sep 17, 2018 at 9:55
  • Use $order->getId() Commented Sep 17, 2018 at 11:04
0

Header:Authorization Bearer Key

use admin token

baseurl/rest/all/V1/orders/orderid

baseurl/rest/all/V1/orderlist?searchCriteria[filter_groups][0][filters][0][field]=customer_id&searchCriteria[filter_groups][0][filters][0][value]=15

4
  • how can i get order_id or entity_id after placing order Commented Sep 17, 2018 at 9:53
  • Use sales_order_place_after event where you can get all order details Commented Sep 17, 2018 at 10:14
  • i am using rest api so how can i get it Commented Sep 17, 2018 at 10:21
  • 1
    You are using rest API to place order ? If yes it will return order id Commented Sep 17, 2018 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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