Showing results for 
Search instead for 
Did you mean: 

Passing orderId to success.phtml


Passing orderId to success.phtml

Im working on module that bypasses checkout if user is logged in and grand total is 0,00€.
Everything is working fine except for one thing.  On success page I don't see the order number.

It seems that in success.phtml $this->getOrderId() dosn't return anything.
I'm sure that I'm doing something wrong in my Observer.php:


class Myproject_Bypasscheckout_Model_Observer extends Varien_Object
    public function beforeCheckout(Varien_Event_Observer $observer)
        // Get cart grand total
        $onepage = Mage::getSingleton('checkout/type_onepage');
        $quote = $onepage->getQuote();
        $quoteData = $quote->getData();

        // Bypass only if grand total is 0€ and user is logged in
        if ($quoteData['grand_total'] == 0 && Mage::getSingleton('customer/session')->isLoggedIn()) {

            // Assign Customer To Sales Order Quote
            $customer = Mage::getSingleton('customer/session')->getCustomer();

            // Configure Notification

            // Set Sales Order Shipping Address
            $billingAddressData = Mage::getModel('customer/address')->load($customer->default_billing)->toArray();
            $billingAddress = $quote->getBillingAddress()->addData($billingAddressData);
            $shippingAddressData = Mage::getModel('customer/address')->load($customer->default_shipping)->toArray();
            $shippingAddress = $quote->getShippingAddress()->addData($shippingAddressData);

            // Collect Rates and Set Shipping & Payment Method

            // Set Sales Order Payment
            $quote->getPayment()->importData(array('method' => 'checkmo'));

            // Collect Totals & Save Quote

            // Create Order From Quote
            $service = Mage::getModel('sales/service_quote', $quote);
            $incrementId = $service->getOrder()->getIncrementId();

            $checkout = $onepage->getCheckout();

            Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl() . 'checkout/onepage/success')->sendResponse();

Re: Passing orderId to success.phtml

I don't see anything wrong so far, except you should wrap the order creating section with try .. catch ..., which is not related to your problem.

Did you check if $incrementId has value in the observer? which event this observer listen to?

Re: Passing orderId to success.phtml

I'll add the try catch.


The event is controller_action_predispatch_checkout_onepage_index.

IncrementId does have value in it.


Just figured out what was wrong. Here is how it should be.

$orderId = $service->getOrder()->getId(); // Added this line
$incrementId = $service->getOrder()->getIncrementId();

$checkout = $onepage->getCheckout();
$checkout->setLastOrderId($orderId); // Not incrementId!!