Reputation: 344
I'm trying to track down the title/delivery method for shipments in my store for use in the tracking popup. In the popup template, I've got a Mage_Shipping_Model_Tracking_Result_Status object that looks like this:
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&AgreeToTermsAndConditions=yes"
}
["_hasDataChanges":protected]=> bool(true)
["_origData":protected]=> NULL
["_idFieldName":protected]=> NULL
["_isDeleted":protected]=> bool(false)
["_oldFieldsMap":protected]=> array(0) { }
["_syncFieldsMap":protected]=> array(0) { }
}
The problem I'm having is that I need to know what the "title" is for the shipment as is seen in the admin panel. In the admin panel, I see this:
+-----------------------+------------------------+------------------------+--------+
| Carrier | Title | Number | Action |
+-----------------------+------------------------+------------------------+--------+
| United Parcel Service | MI Expedited Irregular | 9102969006713002493469 | Delete |
+-----------------------+------------------------+------------------------+--------+
Now what I'm looking for is the title from the table, that of "MI Expedited Irregular." I want that so I can put a check for it in the code so that it uses a different tracking URL then then the one listed in the url variable for the object. But I can't figure out how to use the object I listed above to get a Mage_Sales_Model_Order_Shipment_Track, where I believe the particular piece of data I'm looking for lives. In my latest attempts, I tried this
$forder = Mage::getModel('sales/order')->loadByIncrementId($shipid);
foreach($forder->getShipmentsCollection() as $shipment){
var_dump($shipment);
}
$ship_col = Mage::getResourceModel('sales/order_shipment_collection')->setOrderFilter($forder)->load();
var_dump($ship_col);
foreach($ship_col as $sc){
var_dump($sc);
}
$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());
$ftrack = Mage::getModel('sales/order_shipment_track')->loadById($ship->getId());
foreach($ftrack as $tr){
var_dump($tr);
}
}
In all those tries, all I get is NULL/empty results in the var_dumps. The file I'm trying to add the functionality to is popup.phtml, which is in app/design/frontend/default//template/shipping/tracking.
So I guess the two things I'm trying to find are 1) Where is the "title" field, as is seen in the table that shows on a shipment details page in the admin panel, in the mix of objects and tables that is Magento? 2) How do I get that value so I can run my check against it?
Upvotes: 3
Views: 8828
Reputation: 1686
This worked for me when looking for the custom title:
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$shippingTitle = $order->getTracksCollection()->getFirstItem()->getTitle();
Upvotes: 0
Reputation: 344
So I finally figured this one out. My ultimate goal was I wanted to put in a switch statement for different shipping carriers so that I would always have a tracking link for each shipment. I knew the data that I was looking for lived in the sales_flat_order_shipment table and was normally in a Mage_Sales_Order_Model_Shipment_Track object, but couldn't figure out how to get there from inside app/design/frontend/default//template/shipping/tracking/popup.phtml. After keeping on with var_dumps and reading error_logs and just pure trial and error. Here's the code that I came up with that works.
<?php
$ship_col = Mage::getResourceModel('sales/order_shipment_track_collection')->addAttributeToFilter('track_number', $track->getTracking())->load();
foreach($ship_col as $sc){
$trackMethod = $sc->getTitle();
}
?>
I still have a little more testing to do to verify that everything works nicely when dealing with partial shipments and the like, but this is what I've got for single item shipments and it works like a charm.
Upvotes: 3