how to set order status as 'complete' in magento

前端 未结 3 1978
不思量自难忘°
不思量自难忘° 2021-02-03 12:46

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

相关标签:
3条回答
  • 2021-02-03 13:12

    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();
    
    0 讨论(0)
  • 2021-02-03 13:25

    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();
    
    0 讨论(0)
  • 2021-02-03 13:37

    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();
    }
    
    0 讨论(0)
提交回复
热议问题