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.