'magento order status change

In magento2 back end when I submit shipment the order status will changes from processing to complete but I can't find where the code execute this

can any one tell me where I can find the code?

I use magento2.4.3-p1

I found the code in "vendor/magento/module-sales/Model/Order/Shipment.php" when execute this method “_saveShipment” the status will changel,but I don't know why.



Solution 1:[1]

It's in \Magento\Sales\Model\ResourceModel\Order\Handler\State which is called whenever the Order is saved.

Solution 2:[2]

In "Magento\Sales\Model\ResourceModel\Order" there is a function Save(). Within the function you can retrieve and modify value of 'status' of Order. Writing a plugin is preferable.

di.xml

<type name="Magento\Sales\Model\ResourceModel\Order">
    <plugin name="after_plugin_order_state" type="Vendor\Module\Plugin\PluginName"/>
</type>

PluginName.php

public function afterSave(
    \Magento\Sales\Model\ResourceModel\Order $subject,
     $result,$object
){
    $setCustomStatus = $object->setData('status','Complete');
    return $result
 }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 J Flacks
Solution 2 Ram Narayanan