From b3490e092a5a21b1ce6f3e1e1948ff86785d0186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Caruso?= Date: Thu, 17 May 2018 16:19:01 +0200 Subject: [PATCH] ROOMS-123: Update line item "Booking Dates" value to include time --- .../rooms_booking_manager.commerce.inc | 4 ++-- ...ms_booking_manager.confirmation_override.inc | 4 ++-- .../rooms_booking_manager.install | 17 +++++++++++++++++ .../rooms_booking_manager.module | 8 ++++---- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/modules/rooms_booking_manager/rooms_booking_manager.commerce.inc b/modules/rooms_booking_manager/rooms_booking_manager.commerce.inc index 1421373..54e9665 100644 --- a/modules/rooms_booking_manager/rooms_booking_manager.commerce.inc +++ b/modules/rooms_booking_manager/rooms_booking_manager.commerce.inc @@ -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', ), ), ); diff --git a/modules/rooms_booking_manager/rooms_booking_manager.confirmation_override.inc b/modules/rooms_booking_manager/rooms_booking_manager.confirmation_override.inc index 17c5462..0b5ce29 100644 --- a/modules/rooms_booking_manager/rooms_booking_manager.confirmation_override.inc +++ b/modules/rooms_booking_manager/rooms_booking_manager.confirmation_override.inc @@ -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) { diff --git a/modules/rooms_booking_manager/rooms_booking_manager.install b/modules/rooms_booking_manager/rooms_booking_manager.install index a865cb6..0c5b068 100644 --- a/modules/rooms_booking_manager/rooms_booking_manager.install +++ b/modules/rooms_booking_manager/rooms_booking_manager.install @@ -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); + } + } +} diff --git a/modules/rooms_booking_manager/rooms_booking_manager.module b/modules/rooms_booking_manager/rooms_booking_manager.module index 572c38c..07dda0f 100644 --- a/modules/rooms_booking_manager/rooms_booking_manager.module +++ b/modules/rooms_booking_manager/rooms_booking_manager.module @@ -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); @@ -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;