In Magento quite often you need to get order details from order ID. So in this tutorial I am going to show you how to get order details from order ID. There are two types of order ID’s, one is real order ID and the other is order increment ID. So first I will let you know how to get real order ID from order increment ID.
To Get real order ID from order increment id in Magento:
let’s assume your order increment id is #10001222 and you need to get real order ID, you can use following code:
$orderIncrementId = 10001222; $orderId = Mage::getModel('sales/order') ->loadByIncrementId($orderIncrementId) ->getEntityId();
You can get order details by order increment ID as follow:
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
If you know the real order ID you can get order details by using following code:
$order = Mage::getModel("sales/order")->load($orderId);
To get order total value:
$orderTotalValue = number_format ($order->getGrandTotal(), 2, '.' , $thousands_sep = '');
To get order items collection:
$orderItems = $order->getItemsCollection(); foreach ($orderItems as $item){ $product_id = $item->product_id; $product_sku = $item->sku; $product_price = $item->getPrice(); $product_name = $item->getName(); $_product = Mage::getModel('catalog/product')->load($product_id); $cats = $_product->getCategoryIds(); $category_id = $cats[0]; // just get the first id $category = Mage::getModel('catalog/category')->load($category_id); $category_name = $category->getName(); }
To get shipping method from order:
$shipping_method = $order->getShippingMethod();
To get payment method code from order you can use following code:
$payment_method_code = $order->getPayment()->getMethodInstance()->getCode();
I hope this tutorial will help you to get order details from order ID in Magento.