I want to change the order Status programmatically but when I run the function realTest()
as I mentioned below then it gives me an error Call to a member function setState() on array
in the below function it mentions line number 5. I also tried function use Magento\Sales\Model\Order;
in place of other class as I mentioned in my code but in both scenarios, it gives me the same error also when I tried the array to print_r($orderState)
then it returns me null array.
use \Magento\Sales\Api\OrderRepositoryInterface;
public function realTest(){
try{
$orderId = 000256076;
// obtain the order with the order ID
$order = $this->_orderRepository->get($orderId);
$orderState = \Magento\Sales\Model\Order::STATE_PROCESSING;
$order->setState($orderState)->setStatus(\Magento\Sales\Model\Order::STATE_PROCESSING);
$this->_orderRepository->save($order);
return true;
} catch (\Exception $e){
echo 'Message: ' .$e->getMessage();
// add some logging here
return false;
}
}
print_r($order)
it reutrns me null array