0

Try to change the order state from a file within the Magento root directory.

What I did:

  1. Connected to Magento engine and included the object manager:
    // Start Magento engine
    use Magento\Framework\App\Bootstrap;
    require __DIR__ . '/app/bootstrap.php'; 
    $params = $_SERVER;
    $bootstrap = Bootstrap::create(BP, $params);
    $obj = $bootstrap->getObjectManager();
    $state = $obj->get('Magento\Framework\App\State');
    $state->setAreaCode('frontend');
  1. I already get the order ID from database.

  2. Now I try to change order state:

     $order = $obj->get('Magento\Sales\Model\Order') ->load($orderId);
     $orderState = Order::STATE_PROCESSING;
     $order->setState($orderState)->setStatus(Order::STATE_COMPLETE);
     $order->save();

But this throws error:

Fatal error: Uncaught Error: Class 'Order' not found in [FILE]:633 Stack trace: #0 {main} thrown in [FILE] on line 633

I tried and searched, but had no luck. Thanks for any help!

2
  • which error ????? Aug 25, 2021 at 6:16
  • Fatal error: Uncaught Error: Class 'Order' not found in [FILE]:633 Stack trace: #0 {main} thrown in [FILE] on line 633
    – SoD
    Aug 25, 2021 at 9:10

1 Answer 1

0

Try this :-

$order = $obj->get('Magento\Sales\Model\Order')->load($orderId);
$order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING)
      ->setStatus(\Magento\Sales\Model\Order::STATE_COMPLETE);
$order->save();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.