2

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?

4

2 に答える 2

3

だから私は最終的にこれを理解しました。私の最終的な目標は、さまざまな配送業者の切り替えステートメントを入れて、各配送の追跡リンクを常に持つことでした. 探しているデータが sales_flat_order_shipment テーブルにあり、通常は Mage_Sales_Order_Model_Shipment_Track オブジェクトにあることはわかっていましたが、app/design/frontend/default//template/shipping/tracking/popup 内からそこに到達する方法がわかりませんでした。 .phtml. var_dumps を使い続け、error_logs を読み、純粋に試行錯誤した後。これが私が思いついたコードです。

<?php
    $ship_col = Mage::getResourceModel('sales/order_shipment_track_collection')->addAttributeToFilter('track_number', $track->getTracking())->load();
    foreach($ship_col as $sc){
        $trackMethod = $sc->getTitle();
    }
?>

部分的な出荷などを処理するときにすべてがうまく機能することを確認するために、まだもう少しテストを行う必要がありますが、これは私が単一のアイテムの出荷のために持っているものであり、魅力のように機能します.

于 2013-02-20T19:45:01.640 に答える