0

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.

  • kaushal which version of magento you have – Prashant Barot Aug 3 '16 at 13:40
  • Magento ver. 1.7.0.2 – Kaushal Suthar Aug 3 '16 at 13:41
  • are you added code in your theme ? and also if possible check with template path hint from where that is load – Prashant Barot Aug 3 '16 at 13:45
  • It's a custom created checkout, Let me know if wish to see any code... – Kaushal Suthar Aug 3 '16 at 13:47
2

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/

1

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.

0

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();
}
  • Getting error : Fatal error: Call to a member function getFirstname() on a non-object and an empty array for this : print_r($order->getData()); – Kaushal Suthar Aug 3 '16 at 13:45
0

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();
}
  • As I said magento.stackexchange.com/a/72091/39607 tried this already, But not working I'm getting an empty array. – Kaushal Suthar Aug 3 '16 at 13:35
  • $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastRealOrderId()); I have updated answer. please try this. – Chirag Rajput Aug 3 '16 at 13:43
  • Sorry didn't worked for me getLastRealOrderId() :( – Kaushal Suthar Aug 3 '16 at 13:46
0

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));

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.