function template_preprocess_uc_packing_slip in Ubercart 8.4
Same name and namespace in other branches
- 6.2 shipping/uc_shipping/uc_shipping.module \template_preprocess_uc_packing_slip()
- 7.3 shipping/uc_shipping/uc_shipping.module \template_preprocess_uc_packing_slip()
Preprocess function to make tokens available in the packing slip template.
See also
File
- shipping/
uc_fulfillment/ uc_fulfillment.module, line 72 - Organizes ordered products into packages and sets them up for shipment.
Code
function template_preprocess_uc_packing_slip(&$variables) {
$token_service = \Drupal::token();
$bubbleable_metadata = new BubbleableMetadata();
$tokens = $token_service
->generate('site', [
'logo' => 'logo',
], [], [], $bubbleable_metadata);
$variables['site_logo'] = isset($tokens['logo']) ? $tokens['logo'] : '';
$tokens = $token_service
->generate('store', [
'name' => 'name',
'address' => 'address',
'phone' => 'phone',
], [], [], $bubbleable_metadata);
$variables['store_name'] = $tokens['name'];
$variables['store_address'] = $tokens['address'];
$variables['store_phone'] = $tokens['phone'];
$order = $variables['order'];
$variables['order_link'] = Link::createFromRoute($order
->id(), 'uc_order.user_view', [
'user' => $order
->getOwnerId(),
'uc_order' => $order
->id(),
], [
'absolute' => TRUE,
])
->toString();
$variables['order_email'] = $order
->getEmail();
$variables['billing_address'] = [
'#markup' => $order
->getAddress('billing'),
];
$variables['billing_phone'] = $order
->getAddress('billing')
->getPhone();
$variables['shipping_address'] = [
'#markup' => $order
->getAddress('delivery'),
];
$variables['shipping_phone'] = $order
->getAddress('delivery')
->getPhone();
if (\Drupal::moduleHandler()
->moduleExists('uc_payment')) {
$variables['payment_method'] = \Drupal::service('plugin.manager.uc_payment.method')
->createFromOrder($order)
->cartReviewTitle();
}
else {
$variables['payment_method'] = '';
}
$shipment = $variables['shipment'];
$variables['carrier'] = $shipment
->getCarrier();
$variables['tracking_number'] = $shipment
->getTrackingNumber();
$variables['packages'] = $shipment
->getPackages();
}