cancel
Showing results for 
Search instead for 
Did you mean: 

Passing orderId to success.phtml

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

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()) {
            $onepage->initCheckout();

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

            // Configure Notification
            $quote->setSendCconfirmation(true);

            // 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
            $shippingAddress->setCollectShippingRates(true)
                ->collectShippingRates()
                ->setShippingMethod('freeshipping_freeshipping')
                ->setPaymentMethod('checkmo');

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

            // Collect Totals & Save Quote
            $quote->collectTotals()->save();

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

            $checkout = $onepage->getCheckout();
            $checkout->setLastQuoteId($quote->getId());
            $checkout->setLastSuccessQuoteId($quote->getId());
            $checkout->setLastOrderId($incrementId);
            $checkout->setLastRealOrderId($incrementId);

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

Accepted Solutions

Re: Passing orderId to success.phtml

I'll add the try catch.

 

EDIT:
The event is controller_action_predispatch_checkout_onepage_index.

IncrementId does have value in it.

 

EDIT:
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->setLastQuoteId($quote->getId());
$checkout->setLastSuccessQuoteId($quote->getId());
$checkout->setLastOrderId($orderId); // Not incrementId!!
$checkout->setLastRealOrderId($incrementId);

View solution in original post

2 REPLIES 2

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.

 

EDIT:
The event is controller_action_predispatch_checkout_onepage_index.

IncrementId does have value in it.

 

EDIT:
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->setLastQuoteId($quote->getId());
$checkout->setLastSuccessQuoteId($quote->getId());
$checkout->setLastOrderId($orderId); // Not incrementId!!
$checkout->setLastRealOrderId($incrementId);