Question

I developed a custom module so that customers can choose the logistics methods provided by the plugin, and these logistics methods all have a unified CarrierCode. But how do I know if the order comes from my custom logistics method when the user tracks shipment so that I can provide them with logistics information.

May be I need to change details.phtml in module-shipping, \vendor\magento\module-shipping\view\frontend\templates\tracking\details.phtml .But in this page I don't know which shipping method it use,juse know $track['number'],or $shipmentId in parent page.

So,how can i get shipping method they used?

Was it helpful?

Solution

If I understand you correctly, you are trying to add information based on the carrier code.

When creating a shipment, if you add tracking details, then you have carrier_code in there. Check this table:

Check \vendor\magento\module-sales\view\frontend\templates\email\shipment\track.phtml. This is the file responsible for sending tracking detail in shipment email.

And you can get the carrier code inside the tracking loop:

$_item->getCarrierCode()

To customize this file, just copy the file to your theme:

/app/design/frontend/YourTheme/ThemeName/tempaltes/email/shipment/track.phtml

Hope this helps.

UPDATE

In order to add tracking info to your custom shipping method, you should add getTrackingInfo($trackingNumber) function in your carrier (Namespace/Module/Model/Carrier/YourCarrier.php).

/**
 * Get tracking information. Original return value annotation is misleading.
 *
 * @see \Magento\Shipping\Model\Carrier\AbstractCarrier::isTrackingAvailable()
 * @see \Magento\Shipping\Model\Carrier\AbstractCarrierOnline::getTrackingInfo()
 * @see \Magento\Dhl\Model\Carrier::getTracking()
 * @param string $trackingNumber
 * @return \Magento\Shipping\Model\Tracking\Result\AbstractResult
 */
public function getTrackingInfo($trackingNumber)
{
    /** @var \Magento\Shipping\Model\Tracking\Result\Status $tracking */
    $tracking = $this->trackStatusFactory->create();

    $title = $this->getConfigData('title');

    $tracking->setCarrier($this->_code); //your carrier code
    $tracking->setCarrierTitle($title);
    $tracking->setTracking($trackingNumber);

    //you may want to add the events coming from your api
    $trackEventsData [] =
        [
            'deliverydate' => 'date',
            'deliverytime' => 'time',
            'deliverylocation' => 'location',
            'activity' => 'activity'
        ];
    $tracking->setStatus(isset($trackEventsData[0]) ? $trackEventsData[0]['activity'] : '');
    $tracking->setProgressdetail($trackEventsData);

    return $tracking;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top