function rooms_booking_manager_booked_price in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7
Rules action: set the line item price to the booked price.
1 string reference to 'rooms_booking_manager_booked_price'
- rooms_booking_manager_rules_action_info in modules/
rooms_booking_manager/ rooms_booking_manager.rules.inc - Implements hook_rules_action_info().
File
- modules/
rooms_booking_manager/ rooms_booking_manager.module, line 3065 - Rooms Booking Manager brings together all the pieces required to find a room and book it - including the DrupalCommerce integration
Code
function rooms_booking_manager_booked_price($line_item) {
if ($line_item->type == 'rooms_booking') {
$wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
$amount = $wrapper->rooms_booked_price
->value();
if (is_numeric($amount)) {
$unit_price = commerce_price_wrapper_value($wrapper, 'commerce_unit_price', TRUE);
// Calculate the updated amount and create a price array representing the
// difference between it and the current amount.
$current_amount = $unit_price['amount'];
if (module_exists('commerce_multicurrency')) {
$amount = commerce_currency_convert($amount, commerce_default_currency(), $unit_price['currency_code']);
}
$difference = array(
'amount' => $amount - $current_amount,
'currency_code' => $unit_price['currency_code'],
'data' => array(),
);
// Set the amount of the unit price and add the difference as a component.
$wrapper->commerce_unit_price->amount = $amount;
$wrapper->commerce_unit_price->data = commerce_price_component_add($wrapper->commerce_unit_price
->value(), 'base_price', $difference, TRUE);
}
}
}