how to set order status as 'complete' in magento

前端 未结 3 1979
不思量自难忘°
不思量自难忘° 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: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();
    }
    

提交回复
热议问题