2

This is my php file

public function getget(){

    $orderId = $this->getOrderId();

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderId);
     $payment = $order->getPayment();
    $method = $payment->getMethodInstance();
    $methodTitle = $method->getTitle();
    return $methodTitle;
}

I need to get selected payment method by user but this shows payment method from order. I'm beginner.

2
  • Please can you clarify more your question so its easy understand. Commented Nov 17, 2017 at 7:03
  • On checkout page while selecting payment method I need to get which method is seleted. Above code shows paymentMethod of order I need checkoutSession order
    – Ramesh KR
    Commented Nov 17, 2017 at 7:21

1 Answer 1

-2

Please try this one

  /**
    * @var \Magento\Checkout\Model\Session $_checkoutSession
  */
   $session  = Mage::getSingleton('checkout/session');

   $quote_id = $session->getQuoteId();

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

   $paymentcode = $quote->getPayment()->getMethodInstance()->getCode();
10
  • Fatal error: Uncaught Error: Class 'Magento\Checkout\Block\Mage' not found in /home/rkhomeappliances/public_html/vendor/magento/module-checkout/Block/Onepage.php
    – Ramesh KR
    Commented Nov 17, 2017 at 7:51
  • I'm getting this error
    – Ramesh KR
    Commented Nov 17, 2017 at 7:51
  • I need to get it may you help me I'm beginer
    – Ramesh KR
    Commented Nov 17, 2017 at 7:53
  • magento.stackexchange.com/questions/150595/… Is this the same problem which you are facing Commented Nov 17, 2017 at 8:03
  • $this->_checkoutSession->getQuote()->getPayment()->getMethod(); this returns white screen error
    – Ramesh KR
    Commented Nov 17, 2017 at 8:06

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.