Skip to content

Commit

Permalink
ROOMS-123: Update line item "Booking Dates" value to include time
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolò Caruso committed May 17, 2018
1 parent 3f83c1d commit b3490e0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ function rooms_create_line_item($unit_to_book, AvailabilityAgent $agent, $bookin
$commerce_dates = array(
LANGUAGE_NONE => array(
array(
'value' => $agent->start_date->format('Y-m-d'),
'value2' => $dd->format('Y-m-d'),
'value' => $agent->start_date->format('Y-m-d') . 'T00:00:00',
'value2' => $dd->format('Y-m-d') . 'T00:00:00',
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ function rooms_booking_manager_find_overlapping_line_items($start_date, $end_dat

if ($line_item->type == 'rooms_booking') {

$line_item_start_date = DateTime::createFromFormat('Y-m-d', $line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value']);
$line_item_end_date = DateTime::createFromFormat('Y-m-d', $line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value2']);
$line_item_start_date = new DateTime($line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value']);
$line_item_end_date = new DateTime($line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value2']);

if ($line_item_start_date < $end_date && $line_item_end_date > $start_date &&
$line_item->rooms_booked_unit_id[LANGUAGE_NONE][0]['value'] == $unit_id) {
Expand Down
17 changes: 17 additions & 0 deletions modules/rooms_booking_manager/rooms_booking_manager.install
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,20 @@ function rooms_booking_manager_update_7006() {
variable_set_value('rooms_booking_manager_enquiry_form_confirmation', variable_get_value('rooms_enquiry_form_confirmation'));
variable_delete('rooms_enquiry_form_confirmation');
}

/**
* Update line item "Booking Dates" value to include time.
*/
function rooms_booking_manager_update_7007() {
foreach (commerce_line_item_load_multiple(FALSE, array('type' => 'rooms_booking')) as $line_item) {
if (isset($line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value'])) {
$value = new DateTime($line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value']);
$value2 = new DateTime($line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value2']);

$line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value'] = $value->format('Y-m-d') . 'T00:00:00';
$line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value2'] = $value2->format('Y-m-d') . 'T00:00:00';

field_attach_update('commerce_line_item', $line_item);
}
}
}
8 changes: 4 additions & 4 deletions modules/rooms_booking_manager/rooms_booking_manager.module
Original file line number Diff line number Diff line change
Expand Up @@ -2228,8 +2228,8 @@ function rooms_booking_manager_commerce_checkout_complete($order) {
$line_item = commerce_line_item_load($item_id['line_item_id']);
if ($line_item->type == 'rooms_booking') {
$uc = new \UnitCalendar($line_item->rooms_booked_unit_id[LANGUAGE_NONE][0]['value']);
$start_date = \DateTime::createFromFormat('Y-m-d', $line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value']);
$end_date = \DateTime::createFromFormat('Y-m-d', $line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value2']);
$start_date = new DateTime($line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value']);
$end_date = new DateTime($line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value2']);
$adjusted_end_date = clone($end_date);
$adjusted_end_date->modify('-1 day');
$states_confirmed = $uc->getStates($start_date, $adjusted_end_date);
Expand All @@ -2253,8 +2253,8 @@ function rooms_booking_manager_commerce_checkout_complete($order) {
$booking_type = variable_get('rooms_booking_type', 'standard_booking');
$booking = rooms_booking_create(array('type' => $booking_type));
$booking->created = time();
$booking->start_date = $line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value'];
$booking->end_date = $line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value2'];
$booking->start_date = substr($line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value'], 0, 10);
$booking->end_date = substr($line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value2'], 0, 10);

// Associate it with this order.
$booking->order_id = $order->order_number;
Expand Down

0 comments on commit b3490e0

Please sign in to comment.