Magento 2.4 Track this shipment link error on open Popup
-
15-04-2021 - |
Domanda
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.
Soluzione
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