This function not working because what i'm trying to achieve is if this invoice contain a product with sku "FBA" then assign this status.

Looking forward to hearing from you.

But it doesn't work as i'm getting this:

exception 'Varien_Exception' with message 'Invalid method Mage_Sales_Model_Order_Invoice::addStatusHistoryComment(Array
    [0] => Amazon FBA
    [1] => amazonfba
public function changestatus2($event)
    $_order = $event->getEvent()->getInvoice();
    $_state = 'amazonfba';

    foreach($_order->getAllItems() as $item) {
        $sku = $item->getSku();
        if (substr($sku,-4) == '_FBA') {
        $_order->addStatusHistoryComment('Amazon FBA', $_state)
  • try sales_order_payment_capture instead. – B00MER Sep 3 '16 at 15:03

Problem 1: addStatusHistoryComment belongs to Mage_Sales_Model_Order and not to Mage_Sales_Model_Order_Invoice, so you'll get this error.

Problem 2: if you want to alter order status, you have to do this also in Mage_Sales_Model_Order

If it doesn't matter you can set your comment to the order, instead of the invoice, changig observer to sales_order_save_before.

Problem 3: sales_order_save_before is triggered twice, what results in duplicated comments.

So i came up with following solution ...

public function changestatus2(Varien_Event_Observer $observer)
    $order = $observer->getOrder();
    $status = 'amazonfba';

    if (!$order->getFbaFlag()) {
        foreach ($order->getAllItems() as $item) {
            if (substr($item->getSku(), -4) == '_FBA') {
                $order->addStatusHistoryComment('Amazon FBA', $status);

    $order->setStatus($status); // set status for 2nd fired event
    $order->setFbaFlag(true); // set pseudo-flag, so that comment is only added one time

This adds your comment once and finally set your order status to amazonfba.


This is wrong

$_order = $event->getEvent()->getInvoice();

Need to be

$_order = $event->getEvent()->getInvoice()->getOrder();

Change it and will work.

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.