0

This is my first attempt:

$orderId = 57;
    
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('\Magento\Sales\Model\Order')->load($orderId);
$order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING, true);
$order->setStatus(\Magento\Sales\Model\Order::STATE_PROCESSING);
var_dump($order->getStatus()); // here i can see that it is processing
$order->save(); // if i put this in a try and catch, no exception is thrown

another attempt:

//using OrderRepositoryInterface
$order = $this->orderRepositoryInterface->get(57);
$order->setState('processing')->setStatus('processing');
$this->orderRepositoryInterface->save($order); // if i put this in a try and catch, no exception is thrown

Are they other approaches to try to change the order state and status ? Or am i doing something wrong with my attempts? since they are not working :(

Thank you

1 Answer 1

0

For First code:

$order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING, true); 

is wrong as \Magento\Sales\Model\Order::setState only accept one parameter.

Second code is ok!.

Set status & state using code does not mean that your desire status & state will be set to Order for every save() method of order repository magento check order status at \Magento\Sales\Model\ResourceModel\Order\Handler\State::check .So you have to check at this method why your state & status does not effect.

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.