You are here

function template_preprocess_commerce_invoice_pdf_page in Commerce Invoice 7.2

Preprocess function for the invoice PDF page template.

File

modules/pdf/commerce_invoice_pdf.module, line 305
The Commerce Invoice PDF module.

Code

function template_preprocess_commerce_invoice_pdf_page(&$variables) {

  /** @var Invoice $invoice */
  $invoice = $variables['invoice'];
  $variables['content'] = $invoice
    ->buildContent('pdf', NULL);
  $variables['title'] = commerce_invoice_title($invoice);
  $variables['invoice_date'] = format_date($invoice->invoice_date, 'custom', 'Y-m-d');
  $variables['invoice_due'] = format_date($invoice->invoice_due, 'custom', 'Y-m-d');
  $variables['invoice_number'] = check_plain($invoice
    ->getInvoiceNumber());
  if (!empty($invoice->order_id)) {
    $variables['order_number'] = check_plain($invoice
      ->wrapper()->order->order_number
      ->value());
  }
  $variables['logo'] = '';
  $logo = variable_get('commerce_invoice_pdf_logo', 'misc/druplicon.png');
  if ($logo) {
    $logo = !empty($variables['browser']) ? file_create_url($logo) : drupal_realpath($logo);
    $variables['logo'] = theme('image', [
      'path' => $logo,
    ]);
  }
  $price = $invoice
    ->wrapper()->commerce_invoice_total->amount
    ->value();
  $currency_code = $invoice
    ->wrapper()->commerce_invoice_total->currency_code
    ->value();
  $variables['total'] = commerce_currency_format($price, $currency_code);
  $css_files = variable_get('commerce_invoice_pdf_css_files', array(
    drupal_get_path('module', 'commerce_invoice_pdf') . '/css/pdf.css',
  ));
  $variables['inline_css'] = "";
  foreach ($css_files as $file) {
    $variables['inline_css'] .= file_get_contents($file);
  }
  $settings = variable_get('commerce_invoice_pdf_text_settings', array());
  foreach ([
    'header',
    'footer',
    'text',
  ] as $part) {
    $variables['invoice_' . $part] = isset($settings['invoice_' . $part]) ? $settings['invoice_' . $part] : '';
  }
  $variables['theme_hook_suggestions'][] = 'commerce_invoice_pdf_page';
  $variables['theme_hook_suggestions'][] = 'commerce_invoice_pdf_page__' . $invoice->number_pattern;
}