0

I am with magento 2.3.4, and I want to capture the information:

product

order

client

I would also like to know how I can print the data on the console. I am using the observer when ordering checkout_onepage_controller_success_action

I am trying to capture the information from the observer but nothing shows me

<?php
namespace Nasser\Integracion\Observer;
use Magento\Framework\Event\ObserverInterface;
class Test implements ObserverInterface{

protected $_logger;
protected $requester;
protected $messageManager;
public function __construct(
    \Psr\Log\LoggerInterface $logger,
     \Nasser\Integracion\Helper\Requester $requester,
     \Magento\Framework\Message\ManagerInterface $messageManager
)
{
    $this->_logger=$logger;
    $this->requester=$requester;
    $this->messageManager = $messageManager;
}
public function execute(\Magento\Framework\Event\Observer $observer){
 $data = $observer->getEvent()->getData();
 $this->_logger->info('Data', $data);
// $this->messageManager->addNotice(__('Hola este'));
 $erpId = $this->requester->createPedido([]);
}}

I hope you can help me

1

If you look at the function \Magento\Checkout\Controller\Onepage\Success::execute, you will see the code below:

$this->_eventManager->dispatch(
            'checkout_onepage_controller_success_action',
            [
                'order_ids' => [$session->getLastOrderId()],
                'order' => $session->getLastRealOrder()
            ]
        );

and therefore, you should be able to log 2 things:

$orderIds = $observer->getEvent()->getData('order_ids');
 $this->_logger->info('order_id', print_r($orderIds, true));

$order = $observer->getEvent()->getData('order');
 $this->_logger->info('order', print_r($order->getData(), true));

Now, the second line is a big object, so that may be why you see nothing at the moment.. So, I'd start with order increment id for instance.. or just the data you need

| improve this answer | |

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.