2

I'm trying to create a Module that gets the order data when an order is placed and sends it to a third party using FTP.

I've created an Observer that gets called by the sales_order_place_after event.

My Observer code:

<?php

use Magento\Framework\Event\ObserverInterface;

class Orderobserver implements ObserverInterface
{
    public function __construct(
        \Magento\Quote\Model\QuoteFactory $quoteFactory,
        \Magento\Sales\Model\Order $order,
        \Digitaq\CbFashion\Helper\Data $helper
    )
    {
        $this->_order = $order;
        $this->_helper = $helper;
    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $order = $observer->getEvent()->getOrder();
        $this->_helper->writeShp($order);
    }
}

The observer gets called succesfully and the writeShp method also does, but it's not possible for me to dump the $order variable, as that leads to a redirect to the cart without the order being fulfilled. How can I see this variable so I know what data I can pull?

4 Answers 4

3

Try to log your data by using this way:

protected $logger;
public function __construct(\Psr\Log\LoggerInterface $logger)
{
    $this->logger = $logger;
}

You use debug, exception, system for PSR Logger for example:

$this->logger->info($yourCustomData);
$this->logger->debug($yourCustomData);

Hopefully, this will help you.

2
  • This also redirects me back to the cart with the product still in it. Nothing is logged as well. I tried calling my observer on the checkout_onepage_success event but there is no orderdata available through the observer then. Does anyone have any other suggestions?
    – Digitaq
    Feb 27, 2019 at 14:24
  • some time it need clear cache to work.
    – fudu
    Apr 12, 2019 at 8:31
0

If you add the following you will get a error but you will see what's in the observer.

return var_dump($observer);

0

Temporary print log with new file

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/logtest.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('Simple Text Log'); // Simple Text Log
$logger->info('Array Log'.print_r($myArrayVar, true)); // Array Log
-1

If you are in dire need of seeing data from an observer, You can do it in a dirty/nasty way - You can print it with die(); + var_dump(); in Your Observer class

public function execute(Observer $observer)
    {
        die(var_dump($observer));
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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