4

I am trying to save custom data through observer , My observer is triggering but inside execute method I am getting null.

Observer class

namespace Vendor\Module\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer;

class PaymentAssignData implements ObserverInterface {

    /**
     * @var ObjectManagerInterface
     */
    protected $_objectManager;

    /**
     * @param \Magento\Framework\ObjectManagerInterface $objectManager
     */
    public function __construct(
    \Magento\Framework\ObjectManagerInterface $objectManager,
            \Psr\Log\LoggerInterface $logger
    ) {
        //die(__METHOD__);
        $this->_objectManager = $objectManager;
        $this->logger = $logger;
    }


    public function execute(Observer $observer) {
      $order = $observer->getEvent()->getOrder();
     $quote = $order->getQuote();

       var_dump($quote);exit;



    }

}
1

You can't get the quote using sales_order_save_before you can only get the order:

$order = $observer->getEvent()->getOrder();

Then after that you can do:

$quoteId = $order->getQuoteId();
  • I did the same but getting "NUll" value only. – rajat kara Nov 23 '16 at 11:29
  • post your updated code. @rajatkara – Keyur Shah Nov 23 '16 at 11:31
  • 1
    please check the updated code – rajat kara Nov 23 '16 at 11:45
  • @rajatkara your updated quote is wrong you cannot call $order->getQuote() you can only call $order->getQuoteId() – Raphael at Digital Pianism Nov 23 '16 at 11:48
  • 1
    i want to save my custom field data to quote_payment and sales_order_payment table.how to do that ? – rajat kara Nov 24 '16 at 10:02

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.