4

I'm trying to get user's current selected payment method, in onepage checkout page. I tried the following

$paymentMethod = Mage::getSingleton('checkout/session')->getQuote()->getPayment()->getMethodInstance()->getCode();

but the payment method returned is not correct. Actually it's a method that's not even activated in my store (check/money order).

Why is this happening and how can I get the correct value?

6
  • where are you want this value?
    – Amit Bera
    Nov 12, 2014 at 8:18
  • Mage::getSingleton('checkout/type_onepage')->getPayment()->getMethod()
    – Amit Bera
    Nov 12, 2014 at 8:19
  • @AmitBera that gives "Fatal error: Call to undefined method Mage_Checkout_Model_Type_Onepage::getPayment()"
    – zekia
    Nov 12, 2014 at 8:26
  • it mistake Mage::getSingleton('checkout/type_onepage')->getQuote()->getPayment()->getMethod() and let me where r u want to fetch this value...
    – Amit Bera
    Nov 12, 2014 at 8:29

2 Answers 2

3

Try this code,

$session  = Mage::getSingleton('checkout/session');

$quote_id = $session->getQuoteId();

$quote = Mage::getModel('sales/quote')->load($quote_id );

$paymentcode = $quote->getPayment()->getMethodInstance()->getCode();
4
  • Thank you. I tried it but I'm still getting 'checkmo' as the selected payment method code.
    – zekia
    Nov 12, 2014 at 8:02
  • Try disabling checkmo method from backend.
    – HungryDB
    Nov 12, 2014 at 8:04
  • 2
    Please don't use the "load fixes all" remedy, without thorough explanation why. It results in extra queries and negatively affects performance.
    – user4351
    Nov 12, 2014 at 8:15
  • @HungryDB 'checkmo' is for 'Check - Money Order' which is already disabled
    – zekia
    Nov 12, 2014 at 8:27
2

If customer already selected a payment method in checkout/onepage (or another checkout) and saved it to quote, to get current payment instance:

$methodInstance = Mage::getSingleton('checkout/session')->getQuote()->getPayment();

Now, if you need only the current payment method code:

$methodCode = Mage::getSingleton('checkout/session')->getQuote()->getPayment()->getMethod();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.