Magento

Save shipment tracking information programmatically

Hello Guys,

I am working on project and client have big issues while creating a shipment when products are from different vendors. So when admin will create a shipment than he has to add tracking id based on products in order and he is not able to justifying AWB number for particular vendor so i have searched and came to conclusion to save tracking number before creating shipment and i will find available AWB numbers from the available list of AWB numbers and assign each number for a particular vendor id so in vendor panel it appears correct AWB number. So the courier company can pick up correct shipment from vendor.

Please follow below code to check how you can save tracking number programmatically while creating shipment.

Add below code in your config.xml file.

[php]

<events>
<sales_order_shipment_save_before>
<observers>
<sales_order_shipment_save_before>
<type>singleton</type>
<class>ship/observer</class>
<method>salesOrderShipmentSaveBefore</method>
</sales_order_shipment_save_before>
</observers>
</sales_order_shipment_save_before>
</events>

[/php]

Now, create new observer file under Model folder. File name Observer.php

[php]

$shipment = $observer->getEvent()->getShipment();
$track = Mage::getModel(‘sales/order_shipment_track’)
->setNumber(“123123”) //tracking number / awb number
->setCarrierCode(‘dhl’) //carrier code
->setTitle(‘Dhl’); //carrier title
$shipment->addTrack($track);
$track = Mage::getModel(‘sales/order_shipment_track’)
->setNumber(“234234”) //tracking number / awb number
->setCarrierCode(‘dhl’) //carrier code
->setTitle(‘Dhl’); //carrier title
$shipment->addTrack($track);

[/php]

Now create a shipment from admin panel and tracking number automatically updated for that shiping.

Hope this will help you.

Thanks,
Jignesh