I did find sample codes for Magento 1.x. But I have no idea how to do this on Mag2.
Can anyone describe how to implement this using dependency injection (DI)?
Thanks.
$trackingDetail = array(
'carrier_code' => 'ups',
'title' => 'United Parcel Service',
'number' => 'TORD23254WERZXd3', // Replace with your tracking number
);
$track = Mage::getModel('sales/order_shipment_track')->addData($trackingDetail);
$shipment->addTrack($track);
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($shipment)
->addObject($shipment->getOrder())
->save()