We are doing custom Magento themes, Magento design, custom Magento extensions and creative services through Magento designers & developers for worldwide shop owners.

Last News
Magento add or get tracking number of  particular shipment

Magento add or get tracking number of particular shipment

In magento, if you want add new tracking number to specific shipment , or if you have more than one tracking number assigned for any particular shipment, and you want showing that is the technique :

How add new tracking numbers to specific shipment:

1
2
3
4
5
6
7
8
$shipment = Mage::getModel(sales/order_shipment)->load($id);
$trackingDetail = array(
   'carrier_code' => 'fdx',
   'title' => 'Simple Service',
   'number' => 'ARBHJXG66743', // Replace with your tracking number
);
$track = Mage::getModel('sales/order_shipment_track')->addData($trackingDetail);
$shipment->addTrack($track);

and add now :

1
2
3
4
$transactionSave = Mage::getModel('core/resource_transaction')
    ->addObject($shipment)
    ->addObject($shipment->getOrder())
    ->save();

How get all tracking numbers of specific shipment :

1
2
3
4
5
6
7
$shipment = Mage::getModel(sales/order_shipment)->load($id);
$detailtrack = '';
$alltrackback=$shipment->getAllTracks();
foreach ($alltrackback as $track) {
   $detailtrack .= Mage::helper('sales')->__('SMS Tracking Number').' '.$track->getTrackNumber().' '.Mage::helper('sales')->__('SMS Shipped By').' '.$track->getTitle().'\n';
}
echo $detailtrack;

ohter technique to get all tracking numbers for shipment

1
2
3
4
$shipment = Mage::getModel(sales/order_shipment)->load($id);
$trackings=Mage::getResourceModel('sales/order_shipment_track_collection')->addAttributeToSelect('*')->addAttributeToFilter('parent_id',$shipment->getId());
$allTrackingIds = $trackings->getAllIds();
print_r($allTrackingIds);

Now get only the latest tracking number for shipment

1
2
3
4
5
$shipment = Mage::getModel(sales/order_shipment)->load($id);
$trackingNumbers=Mage::getResourceModel('sales/order_shipment_track_collection')->addAttributeToSelect('*')->addAttributeToFilter('parent_id',$shipment->getId());
$trackingNumbers->getSelect()->order('entity_id desc')->limit(1);
$trackData = $trackingNumbers->getData();
$trackID = $trackData[0]['entity_id'];

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*