0

I have enabled the Purchase Order payment method from magento backend. The PO payment method takes a input field data and stores into Sales_order_payment table as po_number. i want to fetch the same value of the input field after place order and store it into my custom table.

currently i am using the following in my observer for checkout_onepage_controller_success_action event.

protected $_dataObject;

\Magento\Framework\DataObject $data,

$this->_dataObject = $data;

$po_number = $this->_dataObject->getPoNumber();

The current code is not giving me the po number. Please help !!

0

You can get po_number from Payment method object.

namespace YourCompany\YourModule\Observer;

use Magento\Sales\Model\OrderFactory;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class HelloWorld implements ObserverInterface {

    protected $_orderFactory;

    public function __construct(
        OrderFactory $orderFactory
    ) {
        $this->_orderFactory = $orderFactory;
    }


    public function execute(Observer $observer ) {

        $orderIds = $observer->getEvent()->getOrderIds();

        if (count($orderIds)) {
            $orderId = $orderIds[0];
            $order = $this->_orderFactory->create()->load($orderId);
            $poNumber = $order->getPayment()->getPoNumber();
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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