Magento CE

Trying to fulfill a client's far-fetched request. Their previous developer created a module which allows the success/order confirmation page to be a CMS page which then references a PHTML file within the template. It was meant to facilitate programmatic order creation at a later point in time. For now, to confirm customer orders, it no longer uses success.phtml but an arbitrary file.

To over-simplify the question: What does it take to echo a customer's most recent order ID on a CMS page? Inside of this CMS page, it's referencing a core/template PHTML file. I'm able to render any static content from that file without issue but I can't echo any order data.

I attempted to make use of the success.phtml code and several other standard variations without success.

<?php $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId()); ?>

Then just echo $order->getId() somewhere but obviously that does not work out of the box.

How would I proceed to call the most recent order information from a CMS page? Thanks.

1 Answer 1


You can use next code to get last customer order (but it will not work for guest orders):

$orders = Mage::getResourceModel('sales/order_collection')
            ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
            ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
            ->addAttributeToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())
            ->addAttributeToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
            ->addAttributeToSort('created_at', 'desc')


$order = $orders->getFirstItem()
  • 1
    It will be less resource intensive to add a limit to the collection and only fetch 1 record. Your query will result in all the customer order records.
    – ProxiBlue
    Commented Apr 11, 2016 at 22:27
  • Righty, but as practice tell - most customers have only 1 order )) But anyway - you are right. It was just copypaste from "My Recent Orders" block )
    – Neklo.com
    Commented Apr 12, 2016 at 5:58
  • 1
    Most customers have only one order is not a very good assumption. Shoukd assume they have 100's and code accordingly 😆
    – ProxiBlue
    Commented Apr 12, 2016 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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