billwerk_subscriptions-1.x-dev/modules/billwerk_subscriptions_manage/billwerk_subscriptions_manage.module

modules/billwerk_subscriptions_manage/billwerk_subscriptions_manage.module
<?php

/**
 * @file
 * Primary module hooks for billwerk_subscriptions_manage module.
 */

/**
 * Implements hook_theme().
 */
function billwerk_subscriptions_manage_theme($existing, $type, $theme, $path) {
  return [
    'billwerk_order' => [
      'variables' => [
        'id' => NULL,
        'planVariantId' => NULL,
        'planId' => NULL,
        'allowWithoutPaymentData' => NULL,
        'lineitems' => [],
        'coupon' => [],
        'currency' => NULL,
        'total' => NULL,
        'totalVat' => NULL,
        'totalGross' => NULL,
        'nextTotalGross' => NULL,
        'nextTotalGrossDate' => NULL,
        'isTrial' => NULL,
        'planName' => NULL,
        'planVariantName' => NULL,
        'orderType' => NULL,
        'contractCustomFields' => [],
        'customer' => [],
        'userLocale' => 'en',
        'attributes' => [],
        'displayOptions' => [
          'hideSubsequentBilling' => FALSE,
        ],
      ],
    ],
    'billwerk_customer' => [
      'variables' => [
        'companyName' => NULL,
        'firstName' => NULL,
        'lastName' => NULL,
        'addressLine1' => NULL,
        'addressLine2' => NULL,
        'street' => NULL,
        'houseNumber' => NULL,
        'country' => NULL,
        'postalCode' => NULL,
        'city' => NULL,
        'state' => NULL,
        'formattedStreetAddressLine' => NULL,
        'formattedCityAddressLine' => NULL,
        'vatId' => NULL,
        'emailAddress' => NULL,
        'attributes' => [],
      ],
    ],
  ];
}

/**
 * Implements hook_preprocess_HOOK().
 */
function billwerk_subscriptions_manage_preprocess_billwerk_order(&$variables) {
  // We need to format currencies in preprocess because of this bug in core:
  // @see https://www.drupal.org/project/drupal/issues/3419294
  // @see https://www.drupal.org/project/twig_intl/issues/3419285
  // otherwise we would do this in the theme using |format_currency(currency,
  // locale=userLocale), but this is currently unusable due to the core bug.
  if (empty($variables['userLocale'])) {
    throw new Exception('userLocale missing');
  }
  if (empty($variables['currency'])) {
    throw new Exception('currency missing');
  }
  $currencyFormatter = new NumberFormatter($variables['userLocale'], NumberFormatter::CURRENCY);
  $numberFormatter = new NumberFormatter($variables['userLocale'], NumberFormatter::DECIMAL);
  $variables['totalFormatted'] = $currencyFormatter->formatCurrency($variables['total'], $variables['currency']);
  $variables['totalVatFormatted'] = $currencyFormatter->formatCurrency($variables['totalVat'], $variables['currency']);
  $variables['totalGrossFormatted'] = $currencyFormatter->formatCurrency($variables['totalGross'], $variables['currency']);
  $variables['nextTotalGrossFormatted'] = $currencyFormatter->formatCurrency($variables['nextTotalGross'], $variables['currency']);
  if (!empty($variables['lineitems'])) {
    foreach ($variables['lineitems'] as &$lineitem) {
      $lineitem->PricePerUnitFormatted = $currencyFormatter->formatCurrency($lineitem->PricePerUnit, $variables['currency']);
      $lineitem->TotalNetFormatted = $currencyFormatter->formatCurrency($lineitem->TotalNet, $variables['currency']);
      $lineitem->TotalVatFormatted = $currencyFormatter->formatCurrency($lineitem->TotalVat, $variables['currency']);
      $lineitem->TotalGrossFormatted = $currencyFormatter->formatCurrency($lineitem->TotalGross, $variables['currency']);
      // Format Quantity:
      $lineitem->QuantityFormatted = $numberFormatter->format($lineitem->Quantity);
    }
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc