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;

2 Answers 2


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){

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


You can get the tracking number anywhere by using below code if the shipment has been created.

        $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId); 


        $order = Mage::getModel('sales/order')->load($ordeId)
        $shipmentCollection = $order->getShipmentsCollection();

        foreach($shipmentCollection as $shipment){
            echo $shipmentIncrementId = $shipment->getIncrementId();
            $shipment = Mage::getModel('sales/order_shipment')->loadByIncrementId($shipmentIncrementId);

            foreach ($shipment->getAllTracks() as $track) {
               echo "<pre>";
               echo "</pre>";

            foreach ($shipment->getCommentsCollection() as $comment) {
               echo "<pre>";
               echo "</pre>";

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.