How to get Shipment Increment ID by Order ID in Magento
magento, php
Solution
In theory an order can have more than one shipment. But if you make a convention to always have one single shipment per order you can get its increment id like this:
$orderIncrementId = 120000012;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
$shipment = $order->getShipmentsCollection()->getFirstItem();
$shipmentIncrementId = $shipment->getIncrementId();
Problem
Hello Guys. Can someone tell me how to get the shipment increment id by order id in Magento ? I need this because I use an outside php file to add tracking information to a shipment and it needs the shipment id for this. Thank you for all your help. I am using the code below to add tracking info ``` $shipmentIncrementId='300000002'; $trackNumber='123456'; $carrier='custom'; $title='server10'; $shipment = Mage::getModel('sales/order_shipment')->loadByIncrementId($shipmentIncrementId); /* @var $shipment Mage_Sales_Model_Order_Shipment */ $track = Mage::getModel('sales/order_shipment_track') ->setNumber($trackNumber) ->setCarrierCode($carrier) ->setTitle($title); $shipment->addTrack($track); try { $shipment->save(); } catch (Mage_Core_Exception $e) { $thiss->_fault('data_invalid', $e->getMessage()); } return $track->getId(); print_r($shipment); ```