I am trying to know if create shipment option is selected from admin while creating invoice from admin by creating an observer. I have tried


events . My observer is :


namespace Nmaespace\Module\Observer;

class Invoice implements \Magento\Framework\Event\ObserverInterface

 * Execute observer.
 * @param \Magento\Framework\Event\Observer $observer
 * @return $this
public function execute(\Magento\Framework\Event\Observer $observer)

    $invoice = $observer->getEvent()->getInvoice();
    $do_shipment = $invoice->getData('do_shipment');
echo $do_shipment;exit;



After all di compile and everything when i try to create an invoice i am getting empty value here . Can someone please help me how check this.

  • your code is right but problem is not calling your observer so you can check your extension created is perfect or not – Rakesh Donga Feb 28 '19 at 8:34
  • extension is proper .i am able to print other static values in the observer while creating invoice from backend – Melvin Feb 28 '19 at 8:35
  • what should 'do_shipment' be? I have never heard about such a property of a invoice. Try printing $invoice->getIncrementId() and see what happens – HelgeB Feb 28 '19 at 8:39
  • while creating invoice we have a checkbox to create shipment at the same time . That checkbox value i am assuming it be present in 'do_shipment' . – Melvin Feb 28 '19 at 8:44
  • Not sure what you're asking, guess you're trying to get that "do_shipment" value from the form. Right ? – Prathap Gunasekaran Feb 28 '19 at 8:49

Try this, In your observer

namespace Vendor\Module\Observer;                                       
class Classname implements \Magento\Framework\Event\ObserverInterface        
    protected $_request;

    public function __construct(
        \Magento\Framework\App\RequestInterface $request
    ) {
        $this->_request = $request;

    public function execute(
        \Magento\Framework\Event\Observer $observer
    ) {     
        $postdata = $this->_request->getPost();
        $do_shipment = $postdata['invoice']['do_shipment']; 
        echo $do_shipment;

Hope this helps :)

  • 1
    Thanks. I had to call $postdata['invoice']['do_shipment'] and got – Melvin Feb 28 '19 at 10:13

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.