Magento 1.7 – Checkout Success Page: Can’t Get Order ID & Customer ID

checkoutguest-checkoutmagento-1.7

I want to get customer id & order id at order success page.

Already tried this : Success page get customer name and order id ..But not working

In index controller

public function successAction()
    {
        $this->_getState()->setCompleteStep(
                Xx_Multistepcheckout_Model_Type_State::STEP_OVERVIEW
            );
        $this->_getState()->setActiveStep(
            Xx_Multistepcheckout_Model_Type_State::STEP_SUCCESS
            );

        $this->loadLayout();
        $this->_initLayoutMessages('checkout/session');
        $ids = $this->_getCheckout()->getOrderIds();
        Mage::dispatchEvent('checkout_multishipping_controller_success_action', array('order_ids' => $ids));
        $this->renderLayout();
    }

In order success page

$_orderIds = $this->getOrderIds();

But it's not giving any order Id's.

So to get order details I've tried following code in order success page.

$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
print_r($order->getData());

It's also giving me an empty array.

Can you please suggest me what should I can do to get order id and customer id in order success page.

Best Answer

First:

Check if this exist in your code: https://github.com/Mediotype/Magento-1.7.0.2-Community-Edition/blob/master/app/code/core/Mage/Checkout/Block/Success.php

This block show on Success page last order. Then use:

<?php echo $this->getRealOrderId(); ?>

Check this:

<?php
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order = Mage::getSingleton('sales/order')->loadByIncrementId($orderId);
echo "Complete Order detail:<br>".print_r($order->debug(),true)."<br>";
?>

Source: http://www.codexpedia.com/magento/get-last-order-details-from-checkout-session-in-magento/

Related Topic