public function ShipmentController::viewPackage in Ubercart 8.4
Displays the details of a package.
Parameters
\Drupal\uc_fulfillment\PackageInterface $package: The package object.
Return value
array A render array.
1 call to ShipmentController::viewPackage()
- ShipmentController::viewShipment in shipping/
uc_fulfillment/ src/ Controller/ ShipmentController.php - Displays shipment details.
File
- shipping/
uc_fulfillment/ src/ Controller/ ShipmentController.php, line 375
Class
- ShipmentController
- Controller routines for shipments.
Namespace
Drupal\uc_fulfillment\ControllerCode
public function viewPackage(PackageInterface $package) {
$shipment = Shipment::load($package
->getSid());
$build = [
'#type' => 'container',
'#attributes' => [
'class' => [
'order-pane',
'pos-left',
],
],
];
$build['title'] = [
'#type' => 'container',
'#markup' => $this
->t('Package %id:', [
'%id' => $package
->id(),
]),
'#attributes' => [
'class' => [
'order-pane-title',
],
],
];
$rows = [];
$rows[] = [
$this
->t('Contents:'),
[
'data' => [
'#markup' => $package
->getDescription(),
],
],
];
if ($shipment) {
$methods = \Drupal::moduleHandler()
->invokeAll('uc_fulfillment_method');
if (isset($methods[$shipment
->getShippingMethod()])) {
$pkg_type = $methods[$shipment
->getShippingMethod()]['ship']['pkg_types'][$package
->getPackageType()];
}
}
$rows[] = [
$this
->t('Package type:'),
isset($pkg_type) ? $pkg_type : [
'data' => [
'#plain_text' => $package
->getPackageType(),
],
],
];
if ($package
->getLength() && $package
->getWidth() && $package
->getHeight()) {
$units = $package
->getLengthUnits();
$rows[] = [
$this
->t('Dimensions:'),
$this
->t('@l x @w x @h', [
'@l' => uc_length_format($package
->getLength(), $units),
'@w' => uc_length_format($package
->getWidth(), $units),
'@h' => uc_length_format($package
->getHeight(), $units),
]),
];
}
if ($package
->getWeight()) {
$units = $package
->getWeightUnits();
$rows[] = [
$this
->t('Weight:'),
uc_weight_format($package
->getWeight(), $units),
];
}
$rows[] = [
$this
->t('Insured value:'),
[
'data' => [
'#theme' => 'uc_price',
'#price' => $package
->getValue(),
],
],
];
if ($package
->getTrackingNumber()) {
$rows[] = [
$this
->t('Tracking number:'),
[
'data' => [
'#plain_text' => $package
->getTrackingNumber(),
],
],
];
}
if ($shipment && $package
->getLabelImage() && file_exists($package
->getLabelImage()->uri)) {
$rows[] = [
$this
->t('Label:'),
[
'data' => [
'#type' => 'link',
'#title' => $this
->t('Click to view.'),
'#url' => Url::fromUri('admin/store/orders/' . $package
->getOrderId() . '/shipments/labels/' . $shipment
->getShippingMethod() . '/' . $package
->getLabelImage()->uri),
],
],
];
}
else {
$rows[] = [
$this
->t('Label:'),
$this
->t('n/a'),
];
}
$build['package'] = [
'#theme' => 'table',
'#rows' => $rows,
'attributes' => [
'style' => 'width:auto;',
],
];
return $build;
}