I would like to know what is the correct method for change status of order when i create the invoice. I created an observer on the basis of what I saw on the internet :

class statutafterinvoice implements ObserverInterface{

 * Message manager
 * @var \Magento\Framework\Message\ManagerInterface
protected $messageManager;

 * Constructor
 * @param  \Magento\Framework\Message\ManagerInterface $messageManager Message Manager
 * @return void
public function __construct(      
) {
    //$this->messageManager = $messageManager;

 * Display a custom message when customer log in
 * @param  \Magento\Framework\Event\Observer $observer Observer
 * @return void
public function execute(\Magento\Framework\Event\Observer $observer)
    $methode = $observer->getEvent()->getInvoice()->getOrder()->getPayment()->getMethodInstance()->getCode();
        $observer->getEvent()->getInvoice()->getOrder()->setStatus('attente_paiement', true);   



and here is my events.xml :

<?xml version="1.0"?>
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="sales_order_invoice_save_after">
       <observer name="bvr_statut_after_invoice" instance="Acme\BVR\Observer\statutafterinvoice"/>

this code dont't work.

do you know the solution for change the status when i invoice the order? i thank you very much

  • What is the state of your order status ? – Steve Pham Apr 5 '18 at 3:37

Order states.

After order has been placed, it gets New state. At that point, you can Hold it, Ship it, Invoice it or Cancel it, thereby assigning your order Hold, Processing, Processing, or Cancelled state, respectively. Once you ship and invoice, your order receives Completed state.

Now, each of these states can have a separate status, that you can define yourself if System -> Order statuses. In your case, if you want the order to say Dispatched, after you are finished shipping and invoicing, you would add Dispatched order status and assign it to Complete order state. Same goes for any other order states.

Option 1: Normally when an invoice is created (and no shipment is created) it sets the state to processing and the status to the default status (or some other status if that is set in the payment method).

Option 2: If the shipment is already created or if we are talking about virtual products (gift cards or downloadable products or other virtual products) the state switches to complete and the status to de selected default status (by default also complete).

Link ref :- How to define the order status after creating an invoice

| improve this answer | |
  • On magento, i have created an observer which it changed the status of order when i invoiced the order and i I would do the same again on magento2!!! – strauss Sep 8 '16 at 12:53

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.