I am trying to get order details in observer (event: checkout_submit_all_after). I am trying to print the order details in debug.log, but nothing printed.
Please refer this know about my complete module structure. I could change observer class functionality like below for getting order details.
app/code/Gworks/Sms/Observer/LogAddMessage.php
<?php
namespace Gworks\Sms\Observer;
use Magento\Framework\Event\ObserverInterface;
class LogAddMessage implements ObserverInterface
{
protected $_logger;
public function __construct(
\Psr\Log\LoggerInterface $logger, //log injection
array $data = []
) {
$this->_logger = $logger;
// parent::__construct($data);
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$this->_logger->addDebug('getplace oreder event occured successfully!');
}
public function getOrder(\Magento\Framework\Event\Observer $observer)
{
$order = $observer->getEvent()->getOrder();
$order_id = $order->getIncrementId();
$this->logger->addDebug($order_id);
}
}
debug.log
[2016-04-26 10:14:10] main.DEBUG: getplace oreder event occured successfully! {"is_exception":false} []
[2016-04-26 10:14:10] main.DEBUG: cache_invalidate: {"method":"POST","url":"http://magentodev.gworks.mobi/magento2/rest/default/V1/carts/mine/payment-information","invalidateInfo":{"tags":["catalog_category_2","catalog_category_26","catalog_category_30","catalog_category_34","catalog_category"],"mode":"matchingAnyTag"},"is_exception":false} []
when define order details in execute method it will throw the below error while place order
[2016-04-26 11:37:42] main.CRITICAL: exception 'Exception' with message 'Report ID: webapi-571f53065307a; Message: Notice: Array to string conversion in /var/www/html/magento2/vendor/monolog/monolog/src/Monolog/Logger.php on line 277' in /var/www/html/magento2/vendor/magento/framework/Webapi/ErrorProcessor.php:194
Stack trace:
#0 /var/www/html/magento2/vendor/magento/framework/Webapi/ErrorProcessor.php(139): Magento\Framework\Webapi\ErrorProcessor->_critical(Object(Exception))
#1 /var/www/html/magento2/vendor/magento/module-webapi/Controller/Rest.php(163): Magento\Framework\Webapi\ErrorProcessor->maskException(Object(Exception))
#2 /var/www/html/magento2/var/generation/Magento/Webapi/Controller/Rest/Interceptor.php(24): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http))
#3 /var/www/html/magento2/vendor/magento/framework/App/Http.php(115): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#4 /var/www/html/magento2/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
#5 /var/www/html/magento2/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#6 {main} [] []
complete module in Github
Thanks