You are here

function rooms_periodic_pricing_rooms_string_alter in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

Implements hook_rooms_string_alter().

File

modules/rooms_pricing/modules/rooms_periodic_pricing/rooms_periodic_pricing.module, line 82

Code

function rooms_periodic_pricing_rooms_string_alter(&$string_suggestions, $context) {
  if ($context['#purpose'] == 'display_base_price') {
    $string_suggestion = reset($string_suggestions);
    if (module_exists('commerce_multicurrency')) {
      $currency_code = commerce_multicurrency_get_user_currency_code();
    }
    else {
      $currency_code = commerce_default_currency();
    }
    $price = $context['#data']['price'];
    if ($context['#component'] == 'units_per_type_form') {
      $units = reset($context['#data']['units'][$price]);
      $unit = $units['unit'];
      $price_log = $units['price_log'];
    }
    elseif ($context['#component'] == 'book_unit_form_builder') {
      $unit = $context['#data']['unit'];
      $price_log = $context['#data']['price_log'];
    }
    $start_date = $context['#data']['arrival'];
    $end_date = $context['#data']['departure'];
    if (isset($price_log['modifiers']['rooms_periodic_pricing']['dynamic_modifier']['pre'])) {
      $pre_price = $price_log['modifiers']['rooms_periodic_pricing']['dynamic_modifier']['pre'];
      $post_price = $price_log['modifiers']['rooms_periodic_pricing']['dynamic_modifier']['post'];
      $price_amount = ($pre_price - $post_price) * 100;
      if (module_exists('commerce_multicurrency')) {
        $price_amount = commerce_currency_convert($price_amount, commerce_default_currency(), $currency_code);
      }
      $string_suggestion .= ' ' . t('(Reduction of @amount)', array(
        '@amount' => commerce_currency_format($price_amount, $currency_code),
      ));
    }
    $string_suggestions[] = $string_suggestion;
  }
}