Question

I have Magento 2.2 and the Track Order button is not working, when I open any order and I press Track Order button I have this error:

Shipment #000000013

Fatal error: Uncaught Error: Call to undefined method Magento\Framework\Phrase::getTracking() in /home/public_html/vendor/magento/module-shipping/view/frontend/templates/tracking/details.phtml:22 
Stack trace: #0 /home/public_html/vendor/magento/framework/View/TemplateEngine/Php.php(59): include() #1 /home/public_html/vendor/magento/framework/View/Element/Template.php(270): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Framework\View\Element\Template), '/home/public_ht...', Array) #2 /home/public_html/vendor/magento/framework/View/Element/Template.php(300): Magento\Framework\View\Element\Template->fetchView('/home/public_ht...') #3 /home/public_html/vendor/magento/framework/View/Element/AbstractBlock.php(667): Magento\Framework\View\Element\Template->_toHtml() #4 /home/public_html/vendor/magento/framework/View/Layout.php(558): Magento\Framework\View\Element\AbstractBlock->toHtml() #5 /home/public_html/vendor/magento/frame in /home/public_html/vendor/magento/module-shipping/view/frontend/templates/tracking/details.phtml on line 22

In that file details.phtml at the line 22 I have this code:

$number = is_object($track) ? $track->getTracking() : $track['number'];

How I can fix this?

Thanks

Was it helpful?

Solution

Ussually, this error happens because of carrier getTracking() function is not returning the proper value.

You can fix this by modifying the shipping plugin's code located in app/code/<Plugin name>/<Carrier name>/Model/<carrier name>.php

Just remove the getTracking() function, instead use function getTrackingInfo(). Here is the defintion of the function, Just copy paste with necessary modifications.

public function getTrackingInfo($trackingNumber)
{
        $tracking = $this->_trackStatusFactory->create();

        $url = 'http://www.stamps.com/shipstatus/?confirmation=' . $trackingNumber; // this is the tracking URL of stamps.com, replace this with your's

        $tracking->setData([
            'carrier' => $this->_code,
            'carrier_title' => $this->getConfigData('title'),
            'tracking' => $trackingNumber,
            'url' => $url,
        ]);
        return $tracking;
}

OTHER TIPS

The solution provided by Nishad Up works only for Carriers extending AbstractCarrierOnline, for the AbstractCarrier you must add initialization of _trackStatusFactory into the constructor:

protected $_trackStatusFactory;

public function __construct(
    // ..
    \Magento\Shipping\Model\Tracking\Result\StatusFactory $trackStatusFactory
) {
    // ..

    $this->_trackStatusFactory = $trackStatusFactory;
}

I think the fix is easy (vendor/magento/module-shipping/view/frontend/templates/tracking/details.phtml):

<table class="data table order tracking" id="tracking-table-popup-<?php /* @noEscape */ echo is_object($track) ? $track->getTracking() : null; ?>">

instead of

<table class="data table order tracking" id="tracking-table-popup-<?php /* @noEscape */ echo $track->getTracking(); ?>">
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top