When order change status from "x" to "complete" I need save when order was completed. I am trying to achieve this with sales_order_save_commit_after event. Problem is that I can't save order when the change is made. Order is completed when Invoice and Shipment were submitted in admin for particular order. I made custom attribute on order completed_at when date and time need to be store.




public function orderUpdate($observer)
    $order = $observer->getEvent()->getOrder();
    if ($order->getOrigData("status") !== "complete" && $order->getData("status") === "complete") {
        $order->setCompletedAt(date('Y-m-d H:i:s', time()));
        Mage::log(print_r($order->getData(), true));
    return $this;
  • Try to move your code to sales_order_save_before and change your condition to if ($order->getData("status") === "complete" && $order->getCompletedAt() == null) or whatever the completed_at default value is. That way you avoid the problems with saving in the after event and should have the correct date saved only once.
    – HelgeB
    Commented Apr 12, 2019 at 12:51


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.