I am implementing my own payment module for Magento, where I implemented getCheckoutRedirectUrl() method in my payment model.
class My_Module_Model_Payment extends Mage_Payment_Model_Method_Abstract {}
This method is supposed to just return URL of payment gateway where user is redirected to, but I should also append current orderId to this URL.
The problem is am not able to get orderId. I tried solution as already accepted here
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
but I get empty $orderId. So this doesn't seem to work in my method. The call doesn't produce error, so I get an object (for example Mage::getSingleton('checkout/session')->getQuote()->getSubtotal() returns order amount), but orderId is empty.
I also tried:
$order = Mage::getModel('sales/order');
$order->load(Mage::getSingleton('sales/order')->getLastOrderId());
$orderId = $order->getIncrementId();
which again returns empty $orderId.
Any Ideas?
Your question, as written, is illogical.
There is no order id during checkout. While you're checking out, Magento creates a sales/quote
object. This object is used to keep track of quote items. It's not until checkout is complete that a sales/order
object is created from the quote.
The reason getLastOrderId
is returning empty is because no order has been placed.
Restating your question with the point in the checkout process that you're at, and what you're trying to do with the order id may help someone come up with the piece of information that you don't know you need.
Good luck!
Author's solution:
The problem was solved by first getting quote ID from checkout/session:
Mage::getSingleton('checkout/session')->getQuoteId();
and then quote object by quote ID:
$quote = Mage::getModel("sales/quote")->load($quoteId);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With