php - Magento 手动将订单状态更改为 'complete'

标签 php magento

我正在尝试手动更改订单状态以在我的代码中的某个点完成。这是我目前所拥有的:

$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/

相关文章:

magento - 如何删除 Magento Dataflow Import 上传的文件?

php - 如何使用 php 将 mysql 结果转换为 JSON 对象

php - 是否可以防止类似页面加载HTML文件时额外加载JS和CSS文件?

php - codeigniter 插入有条件的表

php - Youtube API 获取视频查询

php - 如何使用 cURL 同时将 GET 数据发送到多个 URL?

events - 如何从外部脚本触发在 config.xml 中的 <frontend> 中监视 <controller_action_predispatch> 的无 Controller 核心 Magento 模块

php - 异步触发 Magento 事件观察器

php - 使用 Magento 2.3.3 p1 后遇到的问题

php - 为每个最终可配置选项动态创建添加到购物车 block ,$this 的帮助程序