Magento – How to get Products name from customer order in Magento

magento-1.9PHP

I have created custom payment gateway to redirect user to an external link where payment will be processed. This is the redirect.phtml which redirect to the external payment gateway

<?php
$order = new Mage_Sales_Model_Order();
$customer = new Mage_Customer_Model_Customer();

$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$customer = Mage::getSingleton('customer/session')->getCustomer();

$order->loadByIncrementId($orderId);
$orderData = Mage::getModel('sales/order')->loadByIncrementId($orderId);

$orderDetails = $order->getData();   // order details
$shippingAddress = $order->getShippingAddress();

$_SESSION['dataArray']['names'] = $orderDetails['customer_lastname']." ".$orderDetails['customer_firstname']." ".$orderDetails['customer_middlename'];
$_SESSION['dataArray']['amount'] = $orderData->getGrandTotal();

?>
  <div class = "row">


    <form name="mygatewayform" class="form-horizontal" method="post" action="<!-- my payment gateway -->"> 
       <input type="hidden" name="merchantid" value="376" />
     <input type="hidden" name="phone_number" value="<?php echo $shippingAddress->getTelephone(); ?>" />

      <input type="hidden" name="orderId" value="<?php echo $orderId; ?>">
      <input type="hidden" name="merch_txnref" value="<?php echo time()."_".$orderId; ?>">
      <input type="hidden" name="amount" value="<?php echo round($orderData->getGrandTotal(), 2); ?>">
      <input type="hidden" name="email_address" value="<?php echo $orderDetails['customer_email'] ?>">
      <input type="hidden" name="last-name" value="<?php echo $orderDetails['customer_lastname'] ?>" > 

      <input type="hidden" name ="other-names" value="<?php echo $orderDetails['customer_firstname']." ".$orderDetails['customer_middlename'] ?>">
      <input type="hidden" name="currency" value="<?php echo $orderData->getOrderCurrencyCode(); ?>">

    </form>
 </div>
</div>
 <script type="text/javascript">
document.mygatewayform.submit();
</script>  

As you can see I have been able to generate

  1. Order Id
  2. Customer Name
  3. Grand Total Amount
  4. Currency

Question

How can i generate the product(s) ordered by the customer, because I need to use it my payment gateway

Thanks

Best Answer

you can get product details from order object as follows:-

$order = Mage::getModel('sales/order')->load($orderId);
foreach($order->getAllVisibleItems() as $item){
    echo $item->getName();
}