You are here

public function UnitPricingCalendar::applyPriceModifiers in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

Apply price modifiers to base price.

Parameters

float $base_price: The price to modify.

int $days: The event duration.

array $reply: A log of prices changes

Return value

float The modified price.

Overrides UnitPricingCalendarInterface::applyPriceModifiers

1 call to UnitPricingCalendar::applyPriceModifiers()
UnitPricingCalendar::calculatePrice in modules/rooms_pricing/includes/rooms_pricing.unit_pricing_calendar.inc
Given a date range determine the cost of the room over that period.

File

modules/rooms_pricing/includes/rooms_pricing.unit_pricing_calendar.inc, line 148
Contains UnitPricingCalendar.

Class

UnitPricingCalendar
Handles querying and updating the pricing information relative to a single bookable unit.

Code

public function applyPriceModifiers($base_price, $days, &$reply) {
  $price = $base_price;
  if (!empty($this->price_modifiers)) {
    foreach ($this->price_modifiers as $source => $modifier) {
      if ($modifier['#type'] == ROOMS_PRICE_SINGLE_OCCUPANCY) {
        $reply['log']['modifiers'][$source][$mod_count][ROOMS_PRICE_SINGLE_OCCUPANCY]['pre'] = $price;
        $reply['log']['modifiers'][$source][$mod_count][ROOMS_PRICE_SINGLE_OCCUPANCY]['amount'] = $this->unit->data['singlediscount'];
        $reply['log']['modifiers'][$source][$mod_count][ROOMS_PRICE_SINGLE_OCCUPANCY]['modifier'] = $modifier;
        $this->unit->data['singlediscount'];
        $price -= $base_price * $this->unit->data['singlediscount'] / 100;
        $reply['log']['modifiers'][$source][ROOMS_PRICE_SINGLE_OCCUPANCY]['post'] = $price;
      }
      elseif ($modifier['#type'] == ROOMS_DYNAMIC_MODIFIER) {
        $reply['log']['modifiers'][$source][ROOMS_DYNAMIC_MODIFIER]['modifier'] = $modifier;
        $reply['log']['modifiers'][$source][ROOMS_DYNAMIC_MODIFIER]['pre'] = $price;
        switch ($modifier['#op_type']) {
          case ROOMS_ADD:
            $price += $modifier['#amount'] * $modifier['#quantity'];
            $reply['log']['modifiers'][$source][ROOMS_DYNAMIC_MODIFIER]['op'] = ROOMS_ADD;
            $reply['log']['modifiers'][$source][ROOMS_DYNAMIC_MODIFIER]['post'] = $price;
            break;
          case ROOMS_ADD_DAILY:
            $price += $modifier['#amount'] * $modifier['#quantity'] * $days;
            $reply['log']['modifiers'][$source][ROOMS_DYNAMIC_MODIFIER]['op'] = ROOMS_ADD_DAILY;
            $reply['log']['modifiers'][$source][ROOMS_DYNAMIC_MODIFIER]['post'] = $price;
            break;
          case ROOMS_SUB:
            $price -= $modifier['#amount'] * $modifier['#quantity'];
            $reply['log']['modifiers'][$source][ROOMS_DYNAMIC_MODIFIER]['op'] = ROOMS_SUB;
            $reply['log']['modifiers'][$source][ROOMS_DYNAMIC_MODIFIER]['post'] = $price;
            break;
          case ROOMS_SUB_DAILY:
            $price -= $modifier['#amount'] * $modifier['#quantity'] * $days;
            $reply['log']['modifiers'][$source][ROOMS_DYNAMIC_MODIFIER]['op'] = ROOMS_SUB_DAILY;
            $reply['log']['modifiers'][$source][ROOMS_DYNAMIC_MODIFIER]['post'] = $price;
            break;
          case ROOMS_REPLACE:
            $price = $modifier['#amount'];
            $reply['log']['modifiers'][$source][ROOMS_DYNAMIC_MODIFIER]['op'] = ROOMS_REPLACE;
            $reply['log']['modifiers'][$source][ROOMS_DYNAMIC_MODIFIER]['post'] = $price;
            break;
          case ROOMS_INCREASE:
            $price += $base_price * ($modifier['#amount'] * $modifier['#quantity']) / 100;
            $reply['log']['modifiers'][$source][ROOMS_DYNAMIC_MODIFIER]['op'] = ROOMS_INCREASE;
            $reply['log']['modifiers'][$source][ROOMS_DYNAMIC_MODIFIER]['post'] = $price;
            break;
          case ROOMS_DECREASE:
            $price -= $base_price * ($modifier['#amount'] * $modifier['#quantity']) / 100;
            $reply['log']['modifiers'][$source][ROOMS_DYNAMIC_MODIFIER]['op'] = ROOMS_DECREASE;
            $reply['log']['modifiers'][$source][ROOMS_DYNAMIC_MODIFIER]['post'] = $price;
            break;
        }
      }
    }
  }
  return $price;
}