Search This Blog

May 14, 2012

Magento: Get Order Information on Success page

We use a lot (I’m overacted here) of tracking codes in order to track our sales. Since, most of store owners want to improve the customers shopping experience to return a higher sale conversion. Data that usually track in a sale transaction are order number, product name, quantity, price, customer info etc.

So how do we get this information on the magento success page? Simple! Just read the following steps and go on with your tracking code.

1. Ok, the first thing that we need to do is to find the success page file in your magento directory. If you use the default template of magento, the file is located: app/design/frontend/default/default/template/checkout/success.phtml

2. Open the file on your favorite editor and let’s start some coding.

3. So, how do we find Order Id, sku, subtotal and customer info.

Getting Order Id:
<?php
    $this->getOrderId()
?>

Getting SKU’s Per Item: You can either use one of the following. In this example we will use model.

a. singleton of check out session
b. model of sales order
<?php
     //loading the order object 
    $orderObj = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());?>
    //get all the items included on the order. 
    $orderItems = $orderObj->getAllItems();

    //do a loop to get the sku of each item
foreach($orderItems as $item)
{
  //you can either echo each sku of the order / you can use array variable to pass items sku’s
  echo  $item->getSku();
}
?>

Getting Subtotal: Using the model above you can use the following code to get the subtotal of your order.

<?php
$orderSubTotal = $orderObj ->subtotal;
?>


Getting Customer info: I already made an article about getting customer info in the past. So if you want to look for it just visit this link.

Have a happy life.:))

3 comments:

Unknown said...

Hi there,
great post, thanks, but do you have any idea how I could go about getting the order ID and subtotal via javascript? I'm using Magento Go which doesn't have great affiliate support, and I want to store these in a cookie so I can recall them again post-order to load a tracking code.
Would really appreciate your help with this if you have a chance?
MAny thanks
Jamie

Janz said...

Hi Jaime,

Thanks for dropping by. You can get the order information using php and pass it to javascript. Please see the example below.

<?php
$order_details = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$adwords_saleamt = $order_details->subtotal;

?>


<!-- Google Code for Purchase Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 435435345;
var google_conversion_language = "en";
var google_conversion_format = "1";
var google_conversion_color = "ffffff";
var google_conversion_label = "qbq2CO7Z4wEQwqO94AM";
var google_conversion_value = 0;
if (<? echo $adwords_saleamt ?>) {
google_conversion_value = <? echo $adwords_saleamt ?>;
}
/* ]]> */
</script>

Hope this will helps you.

-Janzell

Anonymous said...

Hi,

Please check ut extension for order information on the success page:
http://extensions.sashas.org/homepage-products/order-success-page.html