Call to Undefined Method in the Magento\Framework\Phrase::getTracking

Developing customized shipping modules tailored to store-specific requirements is a common task in Magento 2 development.

If you’ve encountered the error: “Call to undefined method Magento\Framework\Phrase::getTracking”
while viewing shipment tracking details in the frontend, don’t worry — you’re in the right place.

Here is a simple solution for this. 

Open the model file from your shipping method extension and simply add the below function:

public function getTrackingInfo($trackings)

{

$result = $this->_trackFactory->create();

$tracking = $this->_trackStatusFactory->create();

$tracking->setCarrier($this->_code);

$tracking->setCarrierTitle("Shipping Title");

$tracking->setTracking($trackings);

$tracking->setUrl('http://www.demo.com/?cn=' . $trackings);

$result->append($tracking);

return $tracking;

}

Where, setUrl creates a clickable URL that redirects the customer to the tracking page.

The getTrackingInfo function generates a tracking object for a shipment and provides a tracking URL that can be displayed to customers or used in the admin panel.

Try this solution out, and I am positive that it will help you solve the error. 

Sanjay Jethva

Article by

Sanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for...