How to Get Order Data by Order ID Programmatically in Magento 2

 Steps to Get Order Data by Order ID Programmatically in Magento 2:

Step 1: Create a file in your Magento root directory at the below path


magento_root_directory\getorderdata.php


And then add the following code snippet


<?php

 

use Magento\Framework\App\Bootstrap;

ini_set('display_errors', TRUE); 

ini_set('display_startup_errors', TRUE);

 

require __DIR__ . '/../app/bootstrap.php';

 

$params = $_SERVER;

 

$bootstrap = Bootstrap::create(BP, $params);

 

$objectManager = $bootstrap->getObjectManager();

 

$state = $objectManager->get('Magento\Framework\App\State');

$state->setAreaCode('frontend');

$registry = $objectManager->get('Magento\Framework\Registry');

 

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

 

$orderId=1; //Your Order Id

 

$order = $objectManager->create('\Magento\Sales\Model\OrderRepository')->get($orderId);

 

echo "<br>-----Your Order Data-----<br>"; 

echo "<br> Entity Id : ".$order->getEntityId(); 

echo "<br> Increment Id : ".$order->getIncrementId(); 

echo "<br> State : ".$order->getState(); 

echo "<br> Status : ".$order->getStatus(); 

echo "<br> StoreId : ".$order->getStoreId(); 

echo "<br> Subtotal : ".$order->getSubtotal();

echo "<br> GrandTotal : ".$order->getGrandTotal();

echo "<br> TotalQtyOrdered : ".$order->getTotalQtyOrdered(); 

echo "<br> OrderCurrencyCode : ".$order->getOrderCurrencyCode(); 

echo "<br>-----Your Customer Data-----<br>"; 

echo "<br> Customer First Name : ".$order->getCustomerFirstname(); 

echo "<br> Customer Last Name : ".$order->getCustomerLastname(); 

echo "<br>-----Your Billing Address Data-----<br>";

echo "<pre>";

print_r($order->getBillingAddress()->getData());echo '<br>';

echo "</pre>";

echo "<br>-----Your Shipping Address Data-----<br>"; 

echo "<pre>";

print_r($order->getShippingAddress()->getData());

echo "</pre>";

 

?>

Comments

Popular posts from this blog

Add Admin User name and Action name in Order Comment Section through Action Performed from Sales Order Grid in Magento 2

How to Update Product Stock Programmatically in Magento 2

How to Set and Get Cookie in Magento 2