I used below event for order save after Observer. This is my events.xml
<event name="checkout_onepage_controller_success_action">
<observer name="sales_order_save_after" instance="[Vendor]\[Module]\Observer\Ordersave" />
</event>
Here is my Observer code
namespace [Vendor]\[Module]\Observer;
class Ordersave implements ObserverInterface {
private $logger;
private $state;
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Psr\Log\LoggerInterface $logger,
\Magento\Framework\App\State $state
) {
$this->_layout = $context->getLayout();
$this->_request = $context->getRequest();
$this->logger = $logger;
$this->_state = $state;
}
public function execute(EventObserver $observer) {
$this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL);
try{
$order_ids = $observer->getEvent()->getOrderIds()[0];
....
....
custom code
}catch (\Exception $e) {
$this->logger->info(' --Exception-- '.$e->getMessage());
}
}
}
Event is triggering and i can place order with my custom code written inside try block but after order placed i am getting like
There has been an error processing your request
Error log record number: Some number
Inside that record i am getting below error.
Area code is not set "1":" vendor\/magento\/framework\/View\/Page\/Config.php
What is issue in my code please someone suggest me