1

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.

3
  • +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
2

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

location of the file would be something like this:

app/code/Vendor/Module/Model/Carrier/YourFile.php

In this file add a the function

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

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

    $result->append($tracking);

    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

2
  • 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.