Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento manually change order status to 'complete'

Tags:

php

magento

I am trying to manually change order status to complete at a certain point in my code. This is what I have so far:

$order = Mage::getModel('sales/order')->load($_GET['orderid']);
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true, 'Pedido completado exitosamente.', true, false)->save();

When I do that I get the error:

The Order state 'complete' must not be set manually.

Ok so I tried this:

$order = Mage::getModel('sales/order')->load($_GET['orderid']);
$order->setStatus("complete");
$order->save();

When I do that I get the error:

Call to a member function getMethodInstance() on a non-object

So how can I manually set the order status to complete.

I tried with the first one commenting out the following lines in Sales/Order.php:

if ($shouldProtectState) {
            if ($this->isStateProtected($state)) {
                Mage::throwException(
                    Mage::helper('sales')->__('The Order State "%s" must not be set manually.', $state)
                );
            }
        }

But no go, I still get the not setting to complete error above.

I am using Magento 1.7.0.2.

like image 775
jfreak53 Avatar asked Jan 31 '13 16:01

jfreak53


People also ask

How do I change my order status in Magento 1?

On your Magento Dashboard, go to stores > Settings > Order Status. From this page, click the “Create New Status” button. Now you will need to enter the Status Code. Your status code must include both letters and numbers.

How can I change order status in Magento 2 programmatically?

$newState = Order::STATE_COMPLETE; $order->setState($newState)->setStatus(Order::COMPLETE); $order->save(); I use the obove code to change the state of an order from processing to complete.


Video Answer


1 Answers

First get the order ID like you already did:

$order = Mage::getModel('sales/order')->load($_GET['orderid']);

and then,

Try

$order->addStatusToHistory(Mage_Sales_Model_Order::STATE_COMPLETE);

OR

$order->setData('state', Mage_Sales_Model_Order::STATE_COMPLETE);
$order->save();

You can't set Order state to COMPLETE or CLOSED manually with setState() method AFAIK.

like image 147
Kalpesh Avatar answered Nov 01 '22 05:11

Kalpesh