Custom THANK YOU page in Magento – success.phtml PART-2

In this post we will try to cover up how to get the cart details on Success Page. This is a second part of our post THANK YOU PAGE. If you are directly reading this post we recommend to refer the previous post before going through this.
The link of the previous post is https://universalcoder.wordpress.com/2014/03/20/custom-thank-you-page-in-magento-success-phtml/

thank-you-page

Now lets start how we will get the Cart Summary in Success Page.

1) Goto : app/design/frontend/YOURTHEME/default/template/checkout/success.phtml
I hope you are already on this page as you have already read the first part of this post šŸ˜‰
2) Here, I am shamelessly pasting the whole code for obtaining Cart detail from my success.phtml. I’ll explain each bit below the code.

<?php
//**********************************Order Details***************************
if($this->getOrderId()):
//echo $this->getOrderId();
//$orderObj = Mage::getModel(‘sales/order’)->loadByIncrementId($this->getOrderId());
$orderItems = $orderObj->getAllVisibleItems();
?>
<div><table >
<thead>
<th>Product Name</th>
<th>Unit Price</th>
<th>Qty</th>
<th>Subtotal</th>
</thead>
<tbody>
<?
$_product = Mage::getModel(‘catalog/product’)->load($items->getProductId());
foreach($orderItems as $items){
$product_small_image_path = Mage::helper(‘catalog/image’)->init($_product, ‘small_image’)->resize(135);
?>
<tr>
<td><span><img src=”<?php echo $product_small_image_path ?>”/></span><? echo $items->getName();?></td>
<?php ?><td><? echo number_format($items->getPrice(),3);?></td><?php
?><td><? echo $items->getQtyOrdered(); ?></td><?php
$totalprice = ($items->getQtyOrdered())*($items->getPrice());
?><td><? echo number_format($totalprice,3); ?></td></tr><?php
}
?>

Code Explanation :

1) $this->getOrderId() : It checks if the order exists or not.
2) $orderItems = $orderObj->getAllItems() : Here $orderItems is an array which contains all information about the products in cart. $orderObj is an object we created for the placed order. I have explained about it in previous post.
3)foreach loop is kept so that each and every product is accessed from the array of cart products ie $orderItems
4) Mage::getModel(‘catalog/product’)->load($items->getProductId()) : It gets the product Id of the product in the array.
5)$product_small_image_path = Mage::helper(‘catalog/image’)->init($_product, ‘small_image’)->resize(135) : It gets the small image of the product and resize function is used to resize the image.
6) number_format($items->getPrice(),3) : gets the price of the product with 3 decimal points. Other price function can be used over here too. It can be found from app/design/frontend/YOURTHEME/default/template/catalog/product/price.phtml
7) $items->getQtyOrdered() : Gets the number of product quantity ordered.
8) number_format($orderObj->getSubtotal(),3) : gets the subtotal of the cart
9) number_format($orderObj->getGrandTotal(),3) : gets the grandtotal of the cart.

Thats all for Success-page. If you any queries or doubts please leave them in comment section. Please provide your feedback and suggestion on it.

Advertisements

9 thoughts on “Custom THANK YOU page in Magento – success.phtml PART-2

    • Thank you for your interest in our blog. You can’t open your account, but you can follow our blog to get latest updates. Please click on the follow our blog button via wordpress or email. I’ll also send you and invitation via email for it.

      Like

  1. Hi,
    Where do we need to put this code exatcly in the phtml file because I get a blank page also…
    Thanks for your article!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s