Question

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.

Was it helpful?

Solution 2

Anyways I've sorted this..

I was using $_orderIds = $this->getOrderIds(); multiple times in a success.phtml so second time it was giving me null value.

So I've just called $this->getOrderIds(); only once in success.phtml file.

OTHER TIPS

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/

In Success.phtml

$orderId = $this->getOrderId();
$order = Mage::getModel('sales/order')->load($orderId);

print_r($order->getData());

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

if($order->getCustomerId() === NULL){
echo $order->getBillingAddress()->getFirstname();
echo $order->getBillingAddress()->getEmail();
echo $order->getShippingAddress()->getFirstname();
echo $order->getShippingAddress()->getEmail();
} else {
$customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
echo $customer->getFirstName();
}

To get the order details on the checkout success page, use this

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

and then retrieve the customer info from the order object like this

//If they have no customer id, they're a guest.
if($order->getCustomerId() === NULL){
echo $order->getBillingAddress()->getFirstname();
echo "<br/>";
echo $order->getBillingAddress()->getLastname();
} else {
//else, they're a normal registered user.
$customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
echo $customer->getDefaultBillingAddress()->getFirstname();
echo "<br/>";
echo $customer->getDefaultBillingAddress()->getLastname();
}

If you get to the success page due a redirect like

$this->_redirect('checkout/onepage/success', array('_secure'=>true));

the getOrderId() is empty. I was facing the same problem today so I'll just add the solution to this task in case someone else is stumbling over the same issue. In your controller you'll probably have something like this. Please pay attention to the comment.

$session = Mage::getSingleton('checkout/type_onepage')->getCheckout();

$quoteId = $reorder->getQuote()->getId(); // just an example
$orderId = Mage::getModel("sales/order")->getCollection()->getLastItem()->getEntityId();
$incrementId = Mage::getModel("sales/order")->getCollection()->getLastItem()->getIncrementId();


$session->setLastSuccessQuoteId($quoteId);
$session->setLastQuoteId($quoteId);
$session->setLastOrderId($orderId); // ***Required, otherwise getOrderId() is empty on success.phtml***
$session->setLastRealOrderId($incrementId);

$this->_redirect('checkout/onepage/success', array('_secure'=>true));
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top