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);
It can be done using Magento\Sales\Api\OrderRepositoryInterface interface, all you need to do is use getList() function to fetch order data by order increment id. That's it.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With