1

Using Magento ver. 2.0.7 I am trying to use this code to change order to the status of "Processing", but i get an error, i think i am missing some prerequisite to call, but i can't figure it out.

[25-Oct-2016 13:11:30 America/Detroit] PHP Fatal error: Class 'Magento\Framework\App\ObjectManager' not found in /chroot/home/testplat/test.platinait.ca/html/pub/orderstatus.php on line 4

<?php

$orderId = 000000193;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('\Magento\Sales\Model\Order')
                           ->load($orderId); 

$order->setState("processing")->setStatus("processing");

$order->save();
Gopal Patel
  • 3,139
  • 2
  • 15
  • 32

2 Answers2

0

We can set order status like.

$orderId = 000000193;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order_status = $objectManager->get('Magento\Sales\Mode\Order')->load($orderId);
$order_status->setStatus('processing');
$order_status->save();

Recommended to do this by creating custom module as well as passing the class in to constructor as a dependency.

Krishna ijjada
  • 8,927
  • 6
  • 41
  • 70
0

You should use 'getResource' method. Direct load, save and delete are deprecated in Mangeto >= 2.1.0.

Example :

$order_status->getResource()->save($order_status);
95623
  • 174
  • 5
  • how does order_status know which order it is working on if your not pulling load($orderId) anymore? (or have i misinterpreted something here) – Adam Cheeseman Oct 25 '16 at 21:03
  • always use getResource for those methods. Or you can just inject OrderRepository and use get($id) and save($order) method – 95623 Oct 26 '16 at 16:24
  • btw: aboute objectManager read this answere : http://magento.stackexchange.com/questions/117098/magento-2-to-use-or-not-to-use-the-objectmanager-directly – 95623 Oct 26 '16 at 16:42