0

I'd like to update the status if an order has any backordered items. I have a custom status setup called "quarantined" and I'd like this set if an order is found. I have tried a few ways to get this working but I am having no luck. This is my observer, I hope someone can point me in the right direction.

$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)
}
  • Show us your config.xml and the system.log error log. It's not clear why you're observer is hanging. In the meantime, I've provided a tentative answer. – musicliftsme Mar 9 '15 at 15:56
2

I'm guessing you are hooking onto an event that triggers on order save, not sales_order_place_after, which is fired once after order is completed. If you did on the former, then you will have an infinite loop, where each order status update will trigger your observer over and over. The latter sounds like could be what's happening.

Show us your config.xml. Try sales_order_place_after if you aren't already using it.

  • sales_order_place_after worked!! Thank you :) I was using sales_order_save_after. – Paul Donnelly Mar 9 '15 at 16:18
0

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

//Order State here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.