<?php
// First we need to the last real order id from the checkout/session and then passing this order id as a parameter to retrieve the order object from sales/order model.
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order = Mage::getSingleton('sales/order')->loadByIncrementId($orderId);
// To get some basic order details, subtotal, shipping cost, discount, tax and grand total.
echo "order subtotal: ".$order->getSubtotal()."<br>";
echo "shipping: ".$order->getShippingAmount()."<br>";
echo "discount: ".$order->getDiscountAmount()."<br>";
echo "tax: ".$order->getTaxAmount()."<br>";
echo "grand total".$order->getGrandTotal()."<br><br><br>";
// To show all the order details, the code below will pull all the order details for this order id from the table sales_flat_order
echo "Complete Order detail:<br>".print_r($order->debug(),true)."<br>";
// To get the order details for each item in the order, the order item detail is stored in the table sales_flat_order_item
$orderItems = array();
foreach($order->getItemsCollection() as $item)
{
//$product = Mage::getModel('catalog/product')->load($item->getProductId());
$row=array();
$row['sku'] = $item->getSku();
$row['original_price'] = $item->getOriginalPrice();
$row['price'] = $item->getPrice();
$row['qty_ordered']= (int)$item->getQtyOrdered();
$row['subtotal']= $item->getSubtotal();
$row['tax_amount']= $item->getTaxAmount();
$row['tax_percent']= $item->getTaxPercent();
$row['discount_amount']= $item->getDiscountAmount();
$row['row_total']= $item->getRowTotal();
$orderItems[]=$row;
}
echo "All items in the order:<br>".print_r($orderItems,true)."<br><br><br>";