I have added custom field on checkout page.
I want to get all the post data, in Checkout success observer,
Here is my observer code
<?php
/**
Author : Disha
**/
namespace Neo\OrderComment\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\RequestInterface;
class Orderneo implements \Magento\Framework\Event\ObserverInterface
{
/** @var \Psr\Log\LoggerInterface **/
protected $_logger;
/** @var \Magento\Sales\Model\Order\Status\HistoryFactory **/
protected $_historyFactory;
/** @var \Magento\Sales\Model\OrderFactory **/
protected $_orderFactory;
/**
* @param \Psr\Log\LoggerInterface
* @param \Magento\Sales\Model\Order\Status\HistoryFactory
* @param \Magento\Sales\Model\OrderFactory
**/
public function __construct(
\Psr\Log\LoggerInterface $logger,
\Magento\Sales\Model\Order\Status\HistoryFactory $historyFactory,
\Magento\Sales\Model\OrderFactory $orderFactory){
$this->_logger = $logger;
$this->_historyFactory = $historyFactory;
$this->_orderFactory = $orderFactory;
}
/**
* Add order comment, to the last placed order
* @param \Magento\Framework\Event\Observer
**/
public function execute(\Magento\Framework\Event\Observer $observer)
{
// Get order id, of last placed order
$orderIds = $observer->getEvent()->getOrderIds();
foreach($orderIds as $orderId){
$order = $this->_orderFactory->create()->load($orderId);
}
echo "<pre>"; print_r($this->getRequest()->getPost());
exit;
}
}
But I am getting this error, as unknown method getRequest(),
Fatal error: Uncaught Error: Call to undefined method Neo\OrderComment\Observer\Orderneo::getRequest() in /var/www/html/magento2/app/code/Neo/OrderComment/Observer/Orderneo.php:42
Stack trace:
#0 /var/www/html/magento2/vendor/magento/framework/Event/Invoker/InvokerDefault.php(73): Neo\OrderComment\Observer\Orderneo->execute(Object(Magento\Framework\Event\Observer))
#1 /var/www/html/magento2/vendor/magento/framework/Event/Invoker/InvokerDefault.php(61): Magento\Framework\Event\Invoker\InvokerDefault->_callObserverMethod(Object(Neo\OrderComment\Observer\Orderneo), Object(Magento\Framework\Event\Observer))
#2 /var/www/html/magento2/vendor/magento/framework/Event/Manager.php(66): Magento\Framework\Event\Invoker\InvokerDefault->dispatch(Array, Object(Magento\Framework\Event\Observer))
#3 /var/www/html/magento2/var/generation/Magento/Framework/Event/Manager/Proxy.php(95): Magento\Framework\Event\Manager->dispatch('checkout_onepag...', Array)
#4 /var/www/html/magento2/vendor/magento/module-checkout/Controller/Onepage/Success.php in /var/www/html/magento2/app/code/Neo/OrderComment/Observer/Orderneo.php on line 42