You are here

public function UPS::getTrackingUrl in Commerce UPS 8.3

Returns a tracking URL for UPS shipments.

Parameters

\Drupal\commerce_shipping\Entity\ShipmentInterface $shipment: The commerce shipment.

Return value

mixed The URL object or FALSE.

Overrides SupportsTrackingInterface::getTrackingUrl

File

src/Plugin/Commerce/ShippingMethod/UPS.php, line 282

Class

UPS
Provides the UPS shipping method.

Namespace

Drupal\commerce_ups\Plugin\Commerce\ShippingMethod

Code

public function getTrackingUrl(ShipmentInterface $shipment) {
  $code = $shipment
    ->getTrackingCode();
  if (!empty($code)) {

    // If the tracking code token exists, replace it with the code.
    if (strstr($this->configuration['options']['tracking_url'], '[tracking_code]')) {
      $url = str_replace('[tracking_code]', $code, $this->configuration['options']['tracking_url']);
      return Url::fromUri($url);
    }

    // Otherwise, append the tracking code to the end of the URL.
    $url = $this->configuration['options']['tracking_url'] . $code;
    return Url::fromUri($url);
  }
  return FALSE;
}