0
<?php $orders = $this->getOrders(); ?>

<div class="dashboard_section dashboard_section--orders" id="orders">
    <div class="heading-group">
        <h2><?php echo $this->__('Recent Orders'); ?></h2>

        <?php if (sizeof($orders->getItems()) > 0): ?>
            <a class="button button--s" href="<?php echo $this->getUrl('sales/order/history'); ?>"><?php echo $this->__('View All'); ?></a>
        <?php endif; ?>
    </div>

    <?php if ( sizeof($orders->getItems()) > 0 ): ?>
        <div class="scroll-x" data-scroll-x="600">
            <div class="scroll-x_liner">
                <table class="table recent-orders-table">
                    <thead>
                        <tr>
                            <th><?php echo $this->__('Date'); ?></th>
                            <th><?php echo $this->__('Status'); ?></th>
                            <th><?php echo $this->__('Total'); ?></th>
                            <th><?php echo $this->__('Order #'); ?></th>
                        </tr>
                    </thead>

                    <tbody>
                        <?php foreach ($orders as $order): ?>
                            <tr>
                                <td><?php echo $this->formatDate($order->getCreatedAtStoreDate(), 'medium'); ?></td>
                                <td><?php echo $order->getStatusLabel(); ?></td>
                                <td><?php echo $order->formatPrice($order->getGrandTotal()); ?></td>
                                <td>
                                  <a href="<?php echo $this->getViewUrl($order); ?>"><?php echo $order->getRealOrderId(); ?> - View</a>
                                  <a class="button button--wide" href="#">Track Package</a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>

Currently I am getting order details by date, but I also need products with name,size,color, price,image inside the table . How can I get this?

1

Once you have $order (Mage_Sales_Model_Order) you can use $order->getAllItems();, which will return an array of all of the items on the order as Mage_Sales_Model_Order_Item. Then, from there, you can get the product model (Mage_Catalog_Model_Product) for the item using getProduct(), which gives you access to all of the product attributes (using magic methods).

Here it is, starting with an order collection:

$orders; // order collection

foreach ($orders as $order) {
    $items = $order->getAllItems(); // array of Mage_Sales_Model_Order_Item
    foreach ($items as $item) {
        $product = $item->getProduct(); // Mage_Catalog_Model_Product
        echo $product->getName(); // you can 'get' any attribute like this
        echo $product->getSize();
        echo $product->getColor();
    }
}

EDIT: To access orders from app/design/frontend/[package]/[theme]/template/customer/acco‌​unt/dashboard.phtml, or any of the sub-templates, you can do the following:

$customerEmail = $this->getCustomer()->getEmail();

$orders = Mage::getModel('sales/order')->getCollection()
    ->addFieldToFilter('customer_email', $customerEmail)
    ->addFieldToSelect('*');
| improve this answer | |
  • Thanks @Tim.This works, But, I want to change my renderer/default.phtml file, so that same UI can get on account page and order page. I want only image, image url, product url, for displya in front end on both account page and order page. So any solution? – Sushant Thorat Aug 1 '17 at 5:01
  • @SushantThorat I'm glad this worked, but I'm not sure about what you are asking now. Are you asking how to access image, image url, and product url? – Tim Cieplowski Aug 1 '17 at 13:38
  • I have ordred product table in order page, I want that same table on account dashboard page. How can I gat this? Pleas suggest any solution ASAP.Thanks. – Sushant Thorat Aug 2 '17 at 4:08
  • @SushantThorat Please see edit to my answer. – Tim Cieplowski Aug 2 '17 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.