如果订单有任何缺陷的项目,我想更新状态。 我有一个称为“隔离”的自定义状态设置,如果找到订单,我会喜欢此设置。 我尝试了几种方法来实现这个工作,但我没有运气。 这是我的观察者,我希望有人能指向正确的方向。

$order = $observer->getEvent()->getOrder();
$items = $order->getAllItems();
$hasBackorderedItems = false;
foreach ($items as $item) {
     if ($item->getQtyBackordered() > 0) {
        $hasBackorderedItems = true;
        break;
     }
}

if ($hasBackorderedItems) {
    // I'm Stuck here. I need to change the current order status to quarantined (which is mapped to the state processing)
}
.

有帮助吗?

解决方案

我猜你正在挂钩到一个触发顺序 保存 ,而不是生成的事件,而不是sales_order_place_after,在订单完成后被解雇一次。如果你在前一边做过,那么你将有一个无限的循环,其中每个订单状态更新都会触发你的观察者一遍又一遍。后者的声音可能是发生的事情。

向我们展示您的config.xml。如果您尚未使用它,请尝试生成sales_order_place_after

其他提示

/app/design/frontend/base/default/template/checkout/success.phtml (或/ / site/app/design/frontend/default/yourtheme/template/checkout/success.phtml)

//订单状态

/*
    const STATE_NEW             = 'new';
    const STATE_PENDING_PAYMENT = 'pending_payment';
    const STATE_PROCESSING      = 'processing';
    const STATE_COMPLETE        = 'complete';
    const STATE_CLOSED          = 'closed';
    const STATE_CANCELED        = 'canceled';
    const STATE_HOLDED          = 'holded';
    const STATE_PAYMENT_REVIEW  = 'payment_review';
 */



// Retrieve order
$_order = new Mage_Sales_Model_Order();
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$_order->loadByIncrementId($orderId);
// Update order
$order = Mage::getModel('sales/order')->loadByIncrementID($orderId);
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true);
$order->save();
// Write your success Massage  here 
.

许可以下: CC-BY-SA归因
scroll top