0

I'm want to change the order state processing to newly creates order state, when invoice is created for a order. I want to do this programatically. Anyone help me with this.

0

Try to using sales_order_invoice_pay event, which is fired in adminhtml & frontend scopes.

Update the order state and and status programmatically in order define the status and state. Initiate order object in the construct function and use that order object in the custom function to update it. For Update order state programmatically in model, get order object from the construct function.

public function __construct(
    \Magento\Sales\Model\Order $order
){
    $this->order = $order;
}
public function updateorder(){
    $order = $this->order;
    $order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING, true);
    $order->setStatus(\Magento\Sales\Model\Order::STATE_PROCESSING);
    $order->addStatusToHistory($order->getStatus(), 'Order processed successfully with reference');
    $order->save();
}

Hope it helps!

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.