Feb 12, 2012
kalpesh

Magento: Get all/latest tracking number of any shipment

In magento, if you have more than one tracking number assigned for any particular shipment, we need to show the latest track number with details to the customer.

Here I will show you how to get all tracking numbers as well as only the latest tracking number for any shipment.

Get all tracking numbers for shipment

1
2
3
$trackings=Mage::getResourceModel('sales/order_shipment_track_collection')->addAttributeToSelect('*')->addAttributeToFilter('parent_id',$shipment->getId());
$allTrackingIds = $trackings->getAllIds();
//Mage::log($allTrackingIds);


Get only the latest tracking number for shipment

1
2
3
4
5
6
$trackings=Mage::getResourceModel('sales/order_shipment_track_collection')->addAttributeToSelect('*')->addAttributeToFilter('parent_id',$shipment->getId());
$trackings->getSelect()->order('entity_id desc')->limit(1);

$trackData = $trackings->getData();
$trackID = $trackData[0]['entity_id'];
//Mage::log($trackID);

2 Comments

  • Thanks! I was looking it.

  • Hi Kalpesh,

    Sorry I’m a beginner with Magento. Can you guide me how do I make this appear in my admin grid? I want to add a new column in the Orders grid where the tracking info of each order appears right next to it.

    Thanks.

Leave a comment

 

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications

Honor

Recognition

Magento top 50 contributors

Magento top 50 contributors

Contributions