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);
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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.