how do i set order status as \'complete\' manually.
I am using the following code, but its giving error saying, The Order State \'complete\' must not be set man
Set order status programmatically:
http://blog.chapagain.com.np/magento-how-to-change-order-status-programmatically/
change order status to 'Completed'
$orderIncrementId = YOUR_ORDER_INCREMENT_ID;
$order = Mage::getModel('sales/order')
->loadByIncrementId($orderIncrementId);
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE,true)->save();
i found a solution for my self,
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
$order->setData('state', "complete");
$order->setStatus("complete");
$history = $order->addStatusHistoryComment('Order was set to Complete by our automation tool.', false);
$history->setIsCustomerNotified(false);
$order->save();
well, the actual way to make order state COMPLETE
is to create invoice
and shipment
, after which the order state auto gets COMPLETE
state. Like:
//create invoice for the order
$invoice = $order->prepareInvoice()
->setTransactionId($order->getId())
->addComment("Invoice created from cron job.")
->register()
->pay();
$transaction_save = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transaction_save->save();
//now create shipment
//after creation of shipment, the order auto gets status COMPLETE
$shipment = $order->prepareShipment();
if( $shipment ) {
$shipment->register();
$order->setIsInProcess(true);
$transaction_save = Mage::getModel('core/resource_transaction')
->addObject($shipment)
->addObject($shipment->getOrder())
->save();
}