4

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

0

4 Answers 4

9

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;
}
2
  • How does this work ? Should I then call getTrackingInfo() in the template ? And what is the $trackingNumber given as a parameter if the goal of the function is to return that number ?
    – Badong
    Commented Jun 12, 2020 at 8:08
  • how is this implemented when you are extending AbstractCarrier ?
    – fmsthird
    Commented Nov 16, 2020 at 10:44
1

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;
}
0

I had the same problem with my Carrier created following the Magento instructions (Add custom shipping carrier) on a 2.4.2 istance.

I solved in this way, merging @Nishad Up and @Iaroslav Glodov solutions:

It need to add getTrackingInfo() method into app/code/<Vendor_Name>/<Module_Name>/Model/Carrier/<Carrier_Name>.php class and it doesn't need to remove any functions (getTracking() ???).

It is very important to initialize _trackFactory and _trackStatusFactory

/**
 * @var Magento\Shipping\Model\Tracking\ResultFactory
 */
protected Magento\Shipping\Model\Tracking\ResultFactory $_trackFactory;

/**
 * @var Magento\Shipping\Model\Tracking\Result\StatusFactory
 */
protected Magento\Shipping\Model\Tracking\Result\StatusFactory $_trackStatusFactory;

public function __construct(
    ..
    Magento\Shipping\Model\Tracking\ResultFactory $trackFactory,
    Magento\Shipping\Model\Tracking\Result\StatusFactory $trackStatusFactory,
    ..
) {
    ..
    $this->_trackFactory = $trackFactory;
    $this->_trackStatusFactory = $trackStatusFactory;
    ..
}

/**
 * @param $tracking_number
 *
 * @return Status
 */
public function getTrackingInfo($tracking_number)
{
    $result = $this->_trackFactory->create();
    $tracking = $this->_trackStatusFactory->create();

    $tracking->setCarrier($this->_code);
    $tracking->setCarrierTitle('Carrier Title');
    $tracking->setTracking($tracking_number);
    $tracking->setUrl('https://carrier_domain.tld/trackId=' . $tracking_number);
    }

    $result->append($tracking);

    return $tracking;
}
-2

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(); ?>">
2
  • there I have this code: <table class="data table order tracking" id="tracking-table-popup-<?= /* @noEscape */ $number ?>">
    – Robert
    Commented May 23, 2018 at 14:32
  • your code is not help me anymore
    – Robert
    Commented May 23, 2018 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.