I was trying to implement a custom shipping label programmatically but I'm getting error below:

Error: Call to undefined method Magento\Framework\Phrase::getTracking()....

I am using \Magento\Sales\Api\Data\ShipmentTrackInterfaceFactory to create tracking and my custom carrier is extending AbstractCarrier.

Everything seems to work fine except for the links that open the pop up. Links are:

Track this shipment and
Track order

both under Shipping & Handling Information and Shipping and Tracking Information.

Update: I found this on github upon googling but I don't think the solution will work for me as this is a custom module.

  • +1 for answer acceptance :) Nov 16 '20 at 12:36
  • @ShoaibMunir no worries. one last, can I pass additional param to getTrackingInfo ?
    – fmsthird
    Nov 16 '20 at 13:56
  • No you can't, getTrackingInfo function should follow \Magento\Shipping\Model\Carrier\CarrierInterface parent function, which has only one parameter i.e $trackings Nov 16 '20 at 18:09

In your custom module's Carrier Model you need to add a function getTrackingInfo

location of the file would be something like this:


In this file add a the function

public function getTrackingInfo($trackings)
    $result = $this->_trackFactory->create();
    $tracking = $this->_trackStatusFactory->create();

    $tracking->setCarrierTitle("Carreir Title");
    $tracking->setUrl('http://www.example.com/?cn=' . $trackings); //This is tracking URL


    return $tracking;

where $this->_trackFactory is the instance of \Magento\Shipping\Model\Tracking\ResultFactory
and $this->_trackStatusFactory is the instance of \Magento\Shipping\Model\Tracking\Result\StatusFactory

This should resolve the error that you are facing

  • 1
    awesome 🎉🎉🎉 makes life easy
    – fmsthird
    Nov 16 '20 at 12:36
  • 1
    Simple and accurate solution. Thanks! Jun 2 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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