/ Published in: PHP
The code snippet below can be placed in any template file or anywhere after the Mage is initialized, and there has to be an order placed before.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?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 // To get the order details for each item in the order, the order item detail is stored in the table sales_flat_order_item foreach($order->getItemsCollection() as $item) { //$product = Mage::getModel('catalog/product')->load($item->getProductId()); $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; }