Want to get the order details programmatically, need to use an object manager. But unfortunately, Magento 2 restricts the direct use of the ObjectManager.
- where you need to get order detail ? on phtml ? what data you have to get data i.e order id ?Pawan– Pawan2021-12-21 12:03:26 +00:00Commented Dec 21, 2021 at 12:03
- Where you want to get Order details?Dhiren Vasoya– Dhiren Vasoya2021-12-21 13:12:46 +00:00Commented Dec 21, 2021 at 13:12
Add a comment |
2 Answers
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.
$orderId = 999;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('\Magento\Sales\Model\OrderRepository')->get($orderId);
print_r($order->getData());