Monday, 16 March 2015

Get Last Order Details Start in magento

<!--Get Last Order Details Start-->
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.
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.






<?php
//**********************************Order Details***************************
if($this->getOrderId()):
$orderObj = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$orderItems = $orderObj->getAllVisibleItems();
?>
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover">
<thead>
<th>Product Image</th>
<th>Product Name</th>
<th>Product Sku</th>
<th>Unit Price</th>
<th>Qty</th>
<th>Subtotal</th>
</thead>
<tbody>
<?php
foreach($orderItems as $items){
$_product = Mage::getModel('catalog/product')->load($items->getProductId());
$product_small_image_path = Mage::helper('catalog/image')->init($_product, 'small_image')->resize(135);
?>
<tr>
<td><img src="<?php echo $product_small_image_path ?> "/></td>
<td><?php echo $items->getName(); ?></td>
<td><?php echo $items->getSku(); ?></td>
<td><?php echo number_format($items->getPrice(),2);?></td>
<td><?php echo number_format($items->getQtyOrdered(),0); ?></td>
<td>
<?php
$totalprice = ($items->getQtyOrdered())*($items->getPrice());
echo number_format($totalprice,2);
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<?php endif;?>

<!--Get Last Order Details End-->

No comments:

Post a Comment