Finding the Shipping Carrier Title in Magento
When working with shipments in your Magento store, you may need to find the title or delivery method for use in tracking popups. This guide will help you locate the “title” field from the admin panel shipment details page and retrieve it programmatically.
Understanding the Shipment Tracking Object
First, let’s examine the Mage_Shipping_Model_Tracking_Result_Status object that contains shipping information:
object(Mage_Shipping_Model_Tracking_Result_Status)#182 (7) {
["_data":protected] => array(5) {
["carrier"] => string(3) "ups"
["carrier_title"] => string(21) "United Parcel Service"
["tracking"] => string(22) "9102969006713002493469"
["popup"] => int(1)
["url"] => string(211) "http://wwwapps.ups.com/WebTracking/processInputRequest?HTMLVersion=5.0&error_carried=true&tracknums_displayed=5&TypeOfInquiryNumber=T&loc=en_US&InquiryNumber1=9102969006713002493469&A
greeToTermsAndConditions=yes"
}
["_hasDataChanges":protected] => bool(true)
["_origData":protected] => NULL
// ... other properties ...
}
In this object, you can see the carrier_title property, which corresponds to the carrier name (“United Parcel Service” in this example). However, we are looking for the shipment title as shown in the admin panel.
Locating the Shipment Title
The shipment title is stored in the sales_shipment_grid table. The relevant fields are:
entity_id: The shipment ID.increment_id: The shipment increment ID (unique identifier).total_qty: The total quantity shipped.created_at: The date and time when the shipment was created.shipping_title: This is the title we’re interested in.
To retrieve this information, you can use Magento’s resource model:
$ship_col = Mage::getResourceModel('sales/order_shipment_collection');
$ship_col->addAttributeToFilter('order_id', $forder->getId());
foreach ($ship_col as $sc) {
$ship = Mage::getModel('sales/order_shipment');
$ship->load($sc->getId());
echo "Shipment Title: {$ship->getShippingTitle()}\n";
}
Replace $forder with your order model instance. The getShippingTitle() method retrieves the desired shipment title.
Verifying the Carrier and Using the Title
Now that you have accessed the shipment title, you can compare it against your shipping carrier to perform specific actions or use different tracking URLs:
if ($shipment->getTracking()->getCarrier() == 'ups' && $shipment->getShippingTitle() == 'MI Expedited Irregular') {
// Use a custom tracking URL for this scenario
// ...
} else {
// Use the default tracking URL
// ...
}
Remember to replace 'ups' and 'MI Expedited Irregular' with your desired carrier code and title, respectively.
Conclusion
To summarize, you need to retrieve the shipment title from the sales_shipment_grid table using Magento’s resource model. Once you have accessed the title, you can check it against the carrier information for further processing or tracking URL selection in your popup.phtml template.
For more advanced customizations and best practices related to Magento development, consider exploring the resources available at https://laravelcompany.com. Their expertise in e-commerce platforms like Magento provides valuable insights into various aspects of store management and customization.