Magento – get tracking number in order history, how

magento-1.8shipment-trackingshipping

I have a carrier that get some info about orders from webservice and return a tracking number, I want to show this tracking number to customers in success page and also in order history

what function must use for this?

I used below functions but do not work

public function getTracking($trackings)
    {
        $authDetails = $this->_getAuthDetails();
        $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
        $order = Mage::getModel('sales/order')->load($orderId);
        $shippingId = $order->getShippingAddress()->getId();
        $address = Mage::getModel('sales/order_address')->load($shippingId);
        $firstname = $address->getFirstname();
        $lastname = $address->getLastname();
        $company = $address->getCompany();
        $jobTel = '0311';
        $homeTel = '0311';
        $mobile = '0913';
        $email = $address->getCustomerEmail();
        $street = $address->getStreetFull();
        $postcode = $address->getPostcode();
        $comment = 'for test';
        $regionId = $address->getRegion();
        $cityId = $address->getCity();
        $orders = '49^Windows Vista Home Edition^25000^100^1';
        $sendType = 0;
        $discount = 0;          

        $getTracking = $authDetails->RegisterOrder($firstname,$lastname,$company,$jobTel,$homeTel,$mobile,$email,$street,$postcode,$comment,$regionId,$cityId,$orders,$sendType,$discount);
        //die(print ($getTracking));

        return $getTracking;
    }

    public function getTrackingInfo($tracking)
    {
        $info = array();

        $result = $this->getTracking($tracking);

        if($result instanceof Mage_Shipping_Model_Tracking_Result){
            if ($trackings = $result->getAllTrackings()) {
                return $trackings[0];
            }
        }
        elseif (is_string($result) && !empty($result)) {
            return $result;
        }

        return false;
    }

Best Answer

If you have assigned this tracking number to the order then you should simply be able to loop through all the trackings attached to a order and call getNumber on each tracking object.

foreach ($order->getTracksCollection() as $_track){
    $_track->getNumber();
}

This is how the default magento code does it in the order history tab in the admin section: app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/History.php