Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top