Take a look at app/design/frontend/base/default/layout/shipping.xml to find the block for this template.
<reference name="content">
<block type="shipping/tracking_popup" name="shipping.tracking.popup" template="shipping/tracking/popup.phtml" />
</reference>
Now if you take a look at Mage_Shipping_Block_Tracking_Popup
you will notice that you can not get the order object directly.
So in your template file try this before your code above
$_order = Mage::getModel('sales/order')->load($this->getOrderId());
I've been trying to solve this via models with so many variation and none of them are working. I am quite tired with this approach, so I have solved it using direct SQL like this:
// Add Shipment Tracking Number If Available
if (!empty($order_info->TrackingNumber))
{
// Get db resources
$resource = Mage::getSingleton('core/resource');
$writeConnection = $resource->getConnection('core_write');
$shipmentTrackTable = $resource->getTableName('sales_flat_shipment_track');
// Insert tracking manually
$writeConnection->query(
"INSERT INTO `$shipmentTrackTable` (`parent_id`, `order_id`, `track_number`, `title`, `carrier_code`, `created_at`, `updated_at`)
VALUES (:parent_id, :order_id, :track_number, :title, 'custom', :created_at, :updated_at)",
array(
'parent_id' => $shipment->getId(),
'order_id' => $order->getId(),
'track_number' => $order_info->TrackingNumber,
'title' => 'My Module Name',
'created_at' => now(),
'updated_at' => now(),
));
}
This works.
Best Answer
You have two requirements here - 1) adding a barcode and 2) adding a tracking number.
Barcode:
Barcodes typically require custom fonts. How are you generating barcodes today? If you find yourself using an external service to render the barcode you can create the image offline and include. Using the font is more complex than the image as you must define a path to font on the server.
This is a good example of the type of work required in a custom module that extends
Mage_Sales_Model_Order_Pdf_Packaging
:Source: http://www.magentocommerce.com/boards/viewthread/15807/
Tracking Number:
Adding the tracking number should be trivial compared to the above solution. The below solution lists tracking number separated 200px vertically from each other. In the same file as the barcode solution above:
3rd party plugin
There are third-party plugins available that allow you to create more flexible Packing Slip templates, etc. - many have barcodes built in. Here's one:
http://www.magentocommerce.com/magento-connect/moogento-pickpack-pick-lists-packing-sheets-invoices-pdfs-fully-customisable-works-with-all-order-statuses.html
Good luck!