0

How do I change the order status NOT STATE after I create an invoice in Magento 2?

I created a custom status called Invoiced, assigned it to state processing.

Status code: processing[Invoiced]

When I submit an invoice I want the order to be assigned to this new status.

What additional steps do I need to do?

0

3 Answers 3

0

use evnt sales_order_invoice_pay which is fired in both frontend and beckend.

Vendor\Module\etc\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_pay">
        <observer name="invoice_pay_after" instance="Vrinsoft\ShippingNoteToSupplier\Observer\InvoicePayAfter" />
    </event>
</config>

Vendor\Module\Observer\InvoicePayAfter.php

<?php


 namespace Vrinsoft\ShippingNoteToSupplier\Observer;

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

class InvoicePayAfter implements \Magento\Framework\Event\ObserverInterface

{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $order = $observer->getEvent()->getInvoice();
        //echo json_encode($order->getData());exit();
    }
}
0

First need to create a an event.xml file in your modules etc directory.

<?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_pay">
   <observer name="fs_invoice_pay_after" instance="Custom\StatusChange\Observer\InvoicePayAfter" />
</event>
</config>

Then you need to create an InvoicePayAfter.php file inside Observer directory like below.

<?php
namespace Custom\StatusChange\Observer;
class InvoicePayAfter implements \Magento\Framework\Event\ObserverInterface {
   
   public function execute(\Magento\Framework\Event\Observer $observer) {

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

      if ($order instanceof \Magento\Framework\Model\AbstractModel) {
            if($order->getState() == 'processing') {
                $order->setStatus('processing');
                $order->save();
            }
        }
   }
}

That's all hope this will help somebody.

0

In your

Vendor\Module\etc\frontend\events.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="sales_order_invoice_pay">
        <observer name="invoice_pay_after" instance="Vendor\Module\Observer\InvoicePayAfter" />
    </event>
</config>

Vendor\Module\Observer\InvoicePayAfter.php

class InvoicePayAfter implements \Magento\Framework\Event\ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
       \\You Can get Your Order Here Now Change its Status using

//it is not this to use here for inoivce //$observer->getOrder(); $order = $observer->getInvoice()->getOrder(); \Or Something Like that } }

Your Answer

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

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