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();
if($methode=="xxx_bvr"){
$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"/>
</event>
</config>
this code dont't work.
do you know the solution for change the status when i invoice the order? i thank you very much