When using the availability search ( http://example.com/booking ) with the hook_rooms_price_modifier_alter() function it works fine on normal page views.

Some of the Units have a sleeping capacity of 2 people. In the search results the Unit has a dropdown to select the number of people staying. Changing this dropdown, the parameter $booking_info has incorrect dates:

Normal page request: 2015-02-15 -- 2015-02-22

Ajax request: 2015-02-15 -- 2015-02-21

I'm also using https://www.drupal.org/project/issues/rooms_availability_constraints which is NOT compatible with the new rooms 1.4.

-- edit --

My actual problem is that for a 14 day stay you get a $10 discount, 21 days $15. So I use the start and end date to calculate the length of stay and modify the price with:


$price_modifiers['my.module'] = [
    '#type' => ROOMS_DYNAMIC_MODIFIER,
    '#quantity' => 1,
    '#op_type' => ROOMS_SUB,
    '#amount' => 10
];

Comments

ITWest-jg’s picture

Issue summary: View changes
acrollet’s picture

Issue summary: View changes
ronald_istos’s picture

Status: Active » Postponed (maintainer needs more info)

Could we have an update here on whether this is still an issue with the latest Rooms? Thanks!

ITWest-jg’s picture

Hi,

Just grabbed the code tagged 7.x-1.7 from github. There is still a problem, it seems that inside hook_rooms_price_modifier_alter(&$price_modifiers, $booking_info)

$booking_info is still incorrect, for the URL:

http://example.com/booking/2015-12-12/2015-12-19/1?type=test&rooms_group_size1=1

$booking_info['end_date'] is 2015-12-18

This only happens for some rooms... weird.


function startsWith($haystack, $needle) {
	// search backwards starting from haystack length characters from the end
	return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE;
}

/**
 * Implements hook_rooms_price_modifier_alter().
 */
function pricing_rooms_price_modifier_alter(&$price_modifiers, $booking_info)
{
	$days = $booking_info['end_date']->diff($booking_info['start_date'])->days;

	if (startsWith($_GET['q'], 'booking/')) {
		$bits = explode('/', $_GET['q']);
		$start = new DateTime($bits[1]);
		$end = new DateTime($bits[2]);
		$count = $start->diff($end)->days;

		if ($count != $days) {
			echo "<h1>ERROR!</h1>";
		}
	}
}