我正在尝试手动更改订单状态以在我的代码中的某个点完成。这是我目前所拥有的:
$order = Mage::getModel('sales/order')->load($_GET['orderid']);
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true, 'Pedido completado exitosamente.', true, false)->save();
当我这样做时,我得到了错误:
The Order state 'complete' must not be set manually.
好的,我试过这个:
$order = Mage::getModel('sales/order')->load($_GET['orderid']);
$order->setStatus("complete");
$order->save();
当我这样做时,我得到了错误:
Call to a member function getMethodInstance() on a non-object
那么如何手动设置订单状态为完成。
我尝试用第一个注释掉 Sales/Order.php
中的以下行:
if ($shouldProtectState) {
if ($this->isStateProtected($state)) {
Mage::throwException(
Mage::helper('sales')->__('The Order State "%s" must not be set manually.', $state)
);
}
}
但是不行,我仍然得到上面的 not setting to complete 错误。
我正在使用 Magento 1.7.0.2。
最佳答案
首先像您一样获取订单 ID:
$order = Mage::getModel('sales/order')->load($_GET['orderid']);
然后,
尝试
$order->addStatusToHistory(Mage_Sales_Model_Order::STATE_COMPLETE);
或
$order->setData('state', Mage_Sales_Model_Order::STATE_COMPLETE);
$order->save();
您不能使用 setState()
方法 AFAIK 手动将订单状态设置为 COMPLETE 或 CLOSED。
关于php - Magento 手动将订单状态更改为 'complete',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14630707/