Commit 4c88bd07 authored by droces's avatar droces

Several fixes, incl. bookings now saving addons

parent 2b4ea542
......@@ -1016,10 +1016,21 @@ Drupal.abookings = {
'field_phone_number': data_object_raw['field_phone_number[0][value]'],
'field_phone_number_alt': data_object_raw['field_phone_number_alt[0][value]'],
'field_promo_code_provided': data_object_raw['field_promo_code_provided[0][value]'],
'field_base_cost': data_object_raw['field_base_cost[0][value]']
'field_base_cost': data_object_raw['field_base_cost[0][value]'],
'field_addons': []
};
// console.log('data_object: ', data_object);
addon_checkboxes = $('input[name^="field_addons"]:checked');
// console.log('addon_checkboxes: ', addon_checkboxes);
addon_checkboxes.each(function(index, checkbox) {
// console.log('checkbox: ', checkbox);
var nid = $(checkbox).attr('value');
data_object.field_addons.push(nid);
});
console.log('data_object: ', data_object);
save_booking(data_object, 'booking');
},
......
......@@ -109,6 +109,7 @@ class Event {
// Parses a string into a DateTime object, optionally forced into the given timezone.
function parseDateTime($string, $timezone=null) {
kint($timezone, '$timezone');
$timezone = $timezone ? $timezone : new DateTimeZone('UTC');
$date = new DateTime(
$string,
......
......@@ -58,8 +58,9 @@ function create_booking_fm_submission($booking_values, $promo_code, $booking_tot
'field_num_nights' => $booking_values->field_num_nights,
'field_phone_number' => $booking_values->field_phone_number,
'field_phone_number_alt' => $booking_values->field_phone_number_alt,
'field_addons' => $booking_values->field_addons,
'field_promo_code_provided' => $promo_code,
'field_base_cost' => $booking_total
'field_base_cost' => $booking_total
]);
// kint($booking, '$booking');
return $booking;
......
......@@ -35,41 +35,6 @@ class BookingController extends ControllerBase {
$response_data = [];
$response_data['is_success'] = FALSE;
// public function post(EntityInterface $entity = NULL) {
// if ($entity == NULL) {
// throw new BadRequestHttpException('No entity content received.');
// }
// if (!$entity->access('create')) {
// throw new AccessDeniedHttpException();
// }
// $definition = $this->getPluginDefinition();
// // Verify that the deserialized entity is of the type that we expect to
// // prevent security issues.
// if ($entity->getEntityTypeId() != $definition['entity_type']) {
// throw new BadRequestHttpException('Invalid entity type');
// }
// // POSTed entities must not have an ID set, because we always want to create
// // new entities here.
// if (!$entity->isNew()) {
// throw new BadRequestHttpException('Only new entities can be created');
// }
// // Only check 'edit' permissions for fields that were actually
// // submitted by the user. Field access makes no difference between 'create'
// // and 'update', so the 'edit' operation is used here.
// foreach ($entity->_restSubmittedFields as $key => $field_name) {
// if (!$entity->get($field_name)->access('edit')) {
// throw new AccessDeniedHttpException("Access denied on creating field '$field_name'");
// }
// }
// $request = \Drupal::requestStack()->getCurrentRequest();
// $request_body = $request->getContent();
// kint($request_body, '$request_body 2');
$request_body = $request->getContent();
// kint($request_body, '$request_body');
......@@ -93,6 +58,7 @@ class BookingController extends ControllerBase {
$nights = $booking_values->field_num_nights;
$booking = create_booking_fm_submission($booking_values, $promo_code_provided, $booking_total);
// kint($booking, '$booking unvalidated');
// Validate the received data before saving.
$violations = $booking->validate();
......
......@@ -74,8 +74,11 @@ class BookingStatsPageController extends ControllerBase {
function get_booking_data($bookable_nid) {
$current_timestamp = time();
// $timezone = drupal_get_user_timezone();
// kint($timezone, '$timezone');
$datetime = \Drupal\Core\Datetime\DrupalDateTime
::createFromFormat('U', $current_timestamp);
// drupal_set_message(t('1'), 'status', FALSE);
// Change to first day of month
$d = intval($datetime->format('d'));
......@@ -242,7 +245,10 @@ function stats_get_revenue($date_ranges, $bookable_nid = NULL) {
$total = 0;
foreach ($results as $rid => $nid) {
$booking = node_load($nid);
$total += floatval($booking->get('field_base_cost')->getValue()[0]['value']);
$booking_base_cost = $booking->get('field_base_cost')->getValue();
if (array_key_exists(0, $booking_base_cost)) {
$total += floatval($booking_base_cost[0]['value']);
}
}
// kint($total, '$total');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment