4

I have created a module that hooks into the

sales_order_shipment_save_after

event. I have tested the hook is working with Mage::log, My question is, how do I get the order id for the shipment that was just created? Edit: I tried the following, but $orderId is returning blank in the log...

public function invoice_and_complete($observer)
{
   $event = $observer->getEvent();
   $orderId = $event->getOrderIds();

   Mage::log($orderId);
}
1
  • Your observer function is going to be called every time you save the shippment object. You have to make a check to make sure that the object didn't exist before (e.g. with function getOrigData). Commented Dec 14, 2015 at 10:16

1 Answer 1

8

For sales_order_shipment_save_after it looks as if it only passes the shipment to you in the getEvent method. From there you should be able to get to the order object - An example:

class Company_Shipmentsave_Model_Observer
{
    public function salesOrderShipmentSaveAfter(Varien_Event_Observer $observer)
    {
            $shipment = $observer->getEvent()->getShipment();
            $order = $shipment->getOrder();

            //do something with order - get the increment id:
            $order->getIncrementId();

            //get all of the order items:
            $items = $order->getAllItems();
            return $this;
    }

}

Source:

https://stackoverflow.com/questions/3164800/my-magento-observer-is-getting-in-endless-loop

Your Answer

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

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