1

Want to get the order details programmatically, need to use an object manager. But unfortunately, Magento 2 restricts the direct use of the ObjectManager.

2
  • where you need to get order detail ? on phtml ? what data you have to get data i.e order id ?
    – Pawan
    Dec 21, 2021 at 12:03
  • Where you want to get Order details? Dec 21, 2021 at 13:12

2 Answers 2

1

Can you try using object Manager

 

$orderId = 1;
  $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
  $order = $objectManager->create('\Magento\Sales\Model\OrderRepository')->get($orderId);

 // Get Order Information

  $order->getEntityId();
  $order->getIncrementId();
  $order->getState();
  $order->getStatus();
  $order->getStoreId();
  $order->getGrandTotal();
  $order->getSubtotal();
  $order->getTotalQtyOrdered();
  $order->getOrderCurrencyCode();

  // get customer details

  $custLastName = $orders->getCustomerLastname();
  $custFirsrName = $orders->getCustomerFirstname();

  // get Billing details  

  $billingaddress = $order->getBillingAddress();
  $billingcity = $billingaddress->getCity();      
  $billingstreet = $billingaddress->getStreet();
  $billingpostcode = $billingaddress->getPostcode();
  $billingtelephone = $billingaddress->getTelephone();
  $billingstate_code = $billingaddress->getRegionCode();

  // get shipping details

  $shippingaddress = $order->getShippingAddress();        
  $shippingcity = $shippingaddress->getCity();
  $shippingstreet = $shippingaddress->getStreet();
  $shippingpostcode = $shippingaddress->getPostcode();      
  $shippingtelephone = $shippingaddress->getTelephone();
  $shippingstate_code = $shippingaddress->getRegionCode();

  $grandTotal = $order->getGrandTotal();
  $subTotal = $order->getSubtotal();

  // fetch specific payment information

  $amount = $order->getPayment()->getAmountPaid();
  $paymentMethod = $order->getPayment()->getMethod();
  $info = $order->getPayment()->getAdditionalInformation('method_title');

  // Get Order Items

  $orderItems = $order->getAllItems();

  foreach ($orderItems as $item) {
    $item->getItemId();
    $item->getOrderId();
    $item->getStoreId();
    $item->getProductId();

    print_r($item->getProductOptions());

    $item->getSku();
    $item->getName();
    $item->getQtyOrdered();
    $item->getPrice();
 }

THANKS.

-2

$orderId = 999;

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

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

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.