Magento – Change Order Status

order-status

How do I change the order status? I do orders that are sometimes picked up and delivered (not just shipped) so I need to change the order statuses to "picked up" and "delivered"

How do I do that? I already created these statuses in the config area.

Best Answer

Below are the status's you can use

const STATE_NEW             = 'new';
const STATE_PENDING_PAYMENT = 'pending_payment';
const STATE_PROCESSING      = 'processing';
const STATE_CLOSED          = 'closed';
const STATE_CANCELED        = 'canceled';
const STATE_HOLDED          = 'holded';
const STATE_PAYMENT_REVIEW  = 'payment_review';

Code for updating the status.

$order = Mage::getModel('sales/order')->load($orderid, 'increment_id');
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true);
$order->save();

Above code will update all the status's except COMPLETE Status. As Order becomes complete only when invoice and shipment is created. Once invoice and shipment is created order will automatically changed to Complete.

so for that you can use below code.

Create Invoice

$invoice = $order->prepareInvoice()
                 ->setTransactionId($order->getId())
                 ->addComment($comment)
                 ->register()
                 ->pay();

$transaction_save = Mage::getModel('core/resource_transaction')
                 ->addObject($invoice)
                 ->addObject($invoice->getOrder());
$transaction_save->save();

create shipmnet

$itemQty =  $order->getItemsCollection()->count();
$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($itemQty);
$shipment = new Mage_Sales_Model_Order_Shipment_Api();
$shipmentId = $shipment->create($orderId);