Magento Coding Solutions

get shipping address , Billing address and item details by orderid programmatic in magento

<?php $orderId=$this->getOrderId();
 $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
 $shipping_address_data = $order->getShippingAddress();
      $billing_address_data = $order->getBillingAddress();
 $country1 = Mage::getModel('directory/country')->loadByCode($shipping_address_data['country_id']);
 $ctryname1=$country1->getName();
 $country2 = Mage::getModel('directory/country')->loadByCode($billing_address_data['country_id']);
 $ctryname2=$country2->getName();

 /**Billing and Shipping Information start**/
 $shipbillhtml='';
 $shipbillhtml.='<table class=orderconftab>';
 $shipbillhtml.='<tr><td><h3>Shipping Address</h3></td><td><h3>Billing Address</h3></td></tr>';
 $shipbillhtml.='<tr><td>'.$shipping_address_data['firstname'].' '.$shipping_address_data['lastname'].'</td><td>'.$billing_address_data['firstname'].' '.$billing_address_data['lastname'].'</td></tr>';
 $shipbillhtml.='<tr><td>'.$shipping_address_data['street'].'</td><td>'.$billing_address_data['street'].'</td></tr>';
 $shipbillhtml.='<tr><td>'.$shipping_address_data['city'].', '.$shipping_address_data['region'].', '.$shipping_address_data['postcode'].'</td><td>'.$billing_address_data['city'].', '.$billing_address_data['region'].', '.$billing_address_data['postcode'].'</td></tr>';
 $shipbillhtml.='<tr><td>'.$ctryname1.'</td><td>'.$ctryname2.'</td></tr>';
 $shipbillhtml.='<tr><td>'.$shipping_address_data['telephone'].'</td><td>'.$billing_address_data['telephone'].'</td></tr>';
      $shipbillhtml.='</table>';
      echo $shipbillhtml;
 /**Billing and Shipping Information end**/

 /**Payment Method Start**/
 $payment_method = $order->getPayment()->getMethodInstance()->getTitle();
      echo '<h3 class=orderconfpm>Payment Method</h3>';
      echo '<p>'.$payment_method.'<p>';
 /**Payment Method end**/
 /**Ordered Item Start**/
      $ordered_items = $order->getAllItems();
      echo '<table class=orderconfdetail>
    <thead>
   <th>Product Name</th>
<th class="a-center">Price</th>
<th class="a-center">Qty</th>
<th class="a-center">Subtotal</th>
</thead>';
      foreach($ordered_items as $item) {
$itemsubtotal=Mage::helper('core')->currency($item->getPrice()*$item->getQtyToInvoice());
$productId=$item->getProductId();
$product = Mage::getModel('catalog/product')->load($productId);
$productMediaConfig = Mage::getModel('catalog/product_media_config');
$thumbnailUrl = $productMediaConfig->getMediaUrl($product->getThumbnail());
$productImage='<img src="'.$thumbnailUrl.'" height="50px" />';
echo '<tr>';
echo '<td>'.$productImage.$item->getName().'</td>';
echo '<td>'.Mage::helper('core')->currency($item->getPrice()).'</td>';
echo '<td>'.$item->getQtyToInvoice().'</td>';
echo '<td>'.$itemsubtotal.'</td>';
echo '</tr>';
}
echo '<tr><td colspan="3">Subtotal</td><td>'.Mage::helper('core')->currency($order->getSubtotal()).'</td></tr>';
echo '</table>';
echo '<h5 class="grand_total">Grand Total: '.Mage::helper('core')->currency($order->getBaseGrandTotal()).'</h5>';
/**Ordered Item end**/
 ?>

No comments:

Post a Comment