1

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?

1

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.

  • 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 at 14:24
  • some time it need clear cache to work. – fudu Apr 12 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);

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.