如何手动将订单状态设置为“完成”。
我正在使用以下代码,但它给出的错误 是,不能手动设置订单状态“完成”。
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE);
$order->save();
如何手动将订单状态设置为“完成”。
我正在使用以下代码,但它给出的错误 是,不能手动设置订单状态“完成”。
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE);
$order->save();
我为自己找到了解决方案,
$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();
好吧,创建订单状态的实际方法COMPLETE
是创建invoice
and shipment
,之后订单状态自动获取COMPLETE
状态。喜欢:
//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();
}
请将对象管理器更改为 di
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$orderRepository = $objectManager->create('\Magento\Sales\Api\OrderRepositoryInterface');
$order = $orderRepository->get($orderId);
$order->setState('awaiting_stock');
$order->setStatus('awaiting_stock');
$orderRepository->save($order);
以编程方式设置订单状态:
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();