I'm trying to customize the Customer Dashboard recent order table. Currently, it is only showing Order ID, Date , Ship to, order total and status.
I'm trying to replace Ship to into product name. Below is my attempt. I'm getting this error "Fatal error: Call to a member function getProductName() on a non-object" I'm very new in magento development. Hope you guys can help.
recent.phtml
<thead>
<tr>
<th class="number"><?php echo $this->__('Order #') ?></th>
<th class="date"><?php echo $this->__('Date') ?></th>
<?php /** <th class="ship"><?php echo $this->__('Ship To') ?></th> **/ ?>
<th class="ship"><?php echo $this->__('Product Name') ?></th>
<th class="total"><span class="nobr"><?php echo $this->__('Order Total') ?></span></th>
<th class="status"><?php echo $this->__('Status') ?></th>
<th class="view"> </th>
</tr>
</thead>
<tbody>
<?php foreach ($_orders as $_order): ?>
<tr>
<td class="number"><?php echo $_order->getRealOrderId() ?></td>
<td class="date"><span class="nobr"><?php echo $this->formatDate($_order->getCreatedAtStoreDate()) ?></span></td>
<?php /** <td class="ship"><?php echo $_order->getShippingAddress() ? $this->escapeHtml($_order->getShippingAddress()->getName()) : ' ' ?></td> **/?>
<td class="ship"><?php echo $this->getProduct()->getProductName(); ?></td>
<td class="total"><?php echo $_order->formatPrice($_order->getGrandTotal()) ?></td>
<td class="status"><em><?php echo $_order->getStatusLabel() ?></em></td>
<td class="a-center view">
<span class="nobr">
<a href="<?php echo $this->getViewUrl($_order) ?>"><?php echo $this->__('View Order') ?></a>
<?php if ($this->helper('sales/reorder')->canReorder($_order)) : ?>
<span class="separator">|</span> <a href="<?php echo $this->getReorderUrl($_order) ?>" class="link-reorder"><?php echo $this->__('Reorder') ?></a>
<?php endif ?>
</span>
</td>
</tr>
<?php endforeach; ?>
</tbody>
Edits
Still not showing anything. Please help
<tbody>
<?php foreach ($_orders as $_order): ?>
<tr>
<td class="number"><?php echo $_order->getRealOrderId() ?></td>
<td class="date"><span class="nobr"><?php echo $this->formatDate($_order->getCreatedAtStoreDate()) ?></span></td>
<?php /** <td class="ship"><?php echo $_order->getShippingAddress() ? $this->escapeHtml($_order->getShippingAddress()->getName()) : ' ' ?></td>**/?>
<?php
$order=Mage::getModel('sales/order')->loadByIncrementId($_order->getRealOrderId());
$items = $order->getAllVisibleItems();
$items = $order->getAllItems();
foreach($items as $item){
$name = $item->getProductName();
}
?>
<td class="ship"><?php echo $name ?></td>
<td class="total"><?php echo $_order->formatPrice($_order->getGrandTotal()) ?></td>
<td class="status"><em><?php echo $_order->getStatusLabel() ?></em></td>
<td class="a-center view">
<span class="nobr">
<a href="<?php echo $this->getViewUrl($_order) ?>"><?php echo $this->__('View Order') ?></a>
<?php if ($this->helper('sales/reorder')->canReorder($_order)) : ?>
<span class="separator">|</span> <a href="<?php echo $this->getReorderUrl($_order) ?>" class="link-reorder"><?php echo $this->__('Reorder') ?></a>
<?php endif ?>
</span>
</td>
</tr>
<?php endforeach; ?>
</tbody>
Best Answer
getProductName()
issales_order_item function which is give products name of a sales item.
In
recent don't showing order products ids
. it only show order if you want to get order products ids then you need load order