【问题标题】:Reopen a complete/closed order in Magento?在 Magento 中重新打开完整/关闭的订单?
【发布时间】:2011-12-01 00:49:23
【问题描述】:

有没有办法在 Magento 中以编程方式重新打开已达到完成或关闭状态的订单?我有以下代码可用于更改订单的状态,但我无法让它为完整或已关闭的订单工作。

// connect to magento
require_once('app/Mage.php');
umask(022);
Mage::app();

// check admin credentials
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
$admin = Mage::getSingleton('admin/session');

if ( $admin->isLoggedIn() ) {
    // update order status
    $orderIncrementId = "100000001";
    $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
    $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save();
}

我得到了当前代码here。在那个页面上它说它是用 Magento 1.3.2.4 测试的,但我使用的是 Magento 1.6.x。也许这就是问题所在?

如果我需要提供更多详细信息,请告诉我,感谢您提供的任何帮助。

【问题讨论】:

    标签: magento orders


    【解决方案1】:

    我不认为您在这里遇到了 Magento 版本问题。

    在特定情况下,Magento 只是不允许将订单状态切换回Mage_Sales_Model_Order::STATE_PROCESSING

    例如,通常您无法将Mage_Sales_Model_Order::STATE_PROCESSING 状态保存到任何已经退款的订单(creditmemos)。在 1.3.2.4 和 1.6.x 中都没有。

    这是设计使然。

    查看Mage_Sales_Model_Order::_checkState(),看看Magento在什么情况下会强制将订单状态分别重置为STATE_COMPLETESTATE_CLOSED

    protected function _checkState()
    {
        if (!$this->getId()) {
            return $this;
        }
    
        $userNotification = $this->hasCustomerNoteNotify() ? $this->getCustomerNoteNotify() : null;
    
        if (!$this->isCanceled()
            && !$this->canUnhold()
            && !$this->canInvoice()
            && !$this->canShip()) {
            if (0 == $this->getBaseGrandTotal() || $this->canCreditmemo()) {
                if ($this->getState() !== self::STATE_COMPLETE) {
                    $this->_setState(self::STATE_COMPLETE, true, '', $userNotification);
                }
            }
            /**
             * Order can be closed just in case when we have refunded amount.
             * In case of "0" grand total order checking ForcedCanCreditmemo flag
             */
            elseif (floatval($this->getTotalRefunded()) || (!$this->getTotalRefunded()
                && $this->hasForcedCanCreditmemo())
            ) {
                if ($this->getState() !== self::STATE_CLOSED) {
                    $this->_setState(self::STATE_CLOSED, true, '', $userNotification);
                }
            }
        }
    
        if ($this->getState() == self::STATE_NEW && $this->getIsInProcess()) {
            $this->setState(self::STATE_PROCESSING, true, '', $userNotification);
        }
        return $this;
    }
    

    回答您的问题:您可以通过使用自己的方法覆盖_checkState() 方法来实现您想要做的事情,该方法允许设置STATE_PROCESSING

    请注意,这很可能会导致创建 Magento 既不知道也不期望或无法处理的新状态上下文。

    如果您的更改造成严重破坏,请不要怪我。你被警告了^^

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-25
      • 2015-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多