function bat_options_get_option_price in Booking and Availability Management Tools for Drupal 7
Same name and namespace in other branches
- 8 modules/bat_options/bat_options.module \bat_options_get_option_price()
Calculate the price for an option.
Parameters
$booking_price:
$option:
$quantity:
$nights:
$persons:
Return value
float
File
- modules/
bat_options/ bat_options.module, line 627
Code
function bat_options_get_option_price($booking_price, $option, $quantity, $nights, $persons = 0) {
$price = 0;
switch ($option['operation']) {
case BAT_OPTIONS_ADD:
$price += $option['value'];
break;
case BAT_OPTIONS_ADD_DAILY:
$price += $option['value'] * $nights;
break;
case BAT_OPTIONS_SUB:
$price -= $option['value'];
break;
case BAT_OPTIONS_SUB_DAILY:
$price -= $option['value'] * $nights;
break;
// NB: This will only be correctly calculated for a single add-on with the replace price operation per order.
case BAT_OPTIONS_REPLACE:
$price = $option['value'] - $booking_price;
break;
case BAT_OPTIONS_INCREASE:
$price += $booking_price * ($option['value'] / 100);
break;
case BAT_OPTIONS_DECREASE:
$price -= $booking_price * ($option['value'] / 100);
break;
case BAT_OPTIONS_ADD_PERSON:
$price += $option['value'] * $persons;
break;
case BAT_OPTIONS_ADD_DAILY_PERSON:
$price += $option['value'] * $nights * $persons;
break;
case BAT_OPTIONS_SUB_PERSON:
$price -= $option['value'] * $persons;
break;
case BAT_OPTIONS_SUB_DAILY_PERSON:
$price -= $option['value'] * $nights * $persons;
break;
}
return $price * 100;
}