Get the current orderId in the magento payment module during checkout

I am implementing my own payment module for Magento, where the getCheckoutRedirectUrl () method was implemented in my payment model.

class My_Module_Model_Payment extends Mage_Payment_Model_Method_Abstract {} 

This method should simply return the URL of the payment gateway where the user is redirected, but I must also add the current orderId to this URL.

The problem is that I cannot get orderId. I tried the solution as already made here

 $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId(); 

but I get an empty $ orderId. So this does not work in my method. The call does not cause an error, so I get an object (for example, Mage :: getSingleton ('checkout / session') β†’ getQuote () β†’ getSubtotal () returns the 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 an empty $ orderId.

Any ideas?

+4
source share
1 answer

Your question, as it is written, is illogical.

In mode, the order identifier is missing . While you are checking, Magento creates a sales/quote object. This object is used to track quotation positions. It is not until the verification that the sales/order object is created from the quote.

Reason getLastOrderId returns empty because the order has not been set.

Repeating your question from the point of view of the verification process you are in and what you are trying to do with the order ID can help someone come up with some of the information that you do not know.

Good luck


Author's solution:

The problem was solved by first getting the quote id from checkout / session:

 Mage::getSingleton('checkout/session')->getQuoteId(); 

and then specify the object by ID:

 $quote = Mage::getModel("sales/quote")->load($quoteId); 
+15
source

Source: https://habr.com/ru/post/1390732/


All Articles