1

I have created a module to save order details to a custom mysql table after checkout completion. All works fine but the order id saves in the format "210"(order_id) instead of "1000000210"(increment_id). How can I get this format? My observer looks like this:

public function execute(Observer $observer)
    {

        $orderId = $observer->getEvent()->getOrderIds()[0]; 
        $order = $this->orderRepository->get($orderId);     
        $this->postSaverModel->create()->doSync($orderId);

    }
2

You can try below code for get order increment id in observer.

$order = $observer->getEvent()->getOrder();
$incrementId = $order->getIncrementId();
  • I have tried this. It does not saves my order data to my custom mysql table though the order is created – Shujaat Shaikh Apr 21 at 13:14
  • @ShujaatShaikh share your full code you have tried. – Kirti Nariya Apr 21 at 13:26
  • This did worked. Thanks! – Shujaat Shaikh Apr 21 at 13:42
0

Why you get order object again in your execute function ? You can get order object in your observer using this below code and get increment id also :

$order = $observer->getEvent()->getOrder(); // Order object
$order_incrementId = $order->getIncrementId(); //Increment Id
  • I have tried this. It does not saves my order data to my custom mysql table though the order is created – Shujaat Shaikh Apr 21 at 13:14

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.