Qloapps / QloApps

QloApps is a Free and Open-source hotel management and reservation system to take a hotel business online. QloApps offers a Property Management System (PMS), a Booking Engine, and an attractive Hotel Website. Elevate hotel operations with QloApps to streamline processes and provide an enhanced experience for both hoteliers and guests.
https://qloapps.com
Open Software License 3.0
4.55k stars 503 forks source link

Bug: Null quantity. #74

Closed wdammak closed 5 years ago

wdammak commented 5 years ago

https://demo.qloapps.com/home/11-super-delux-rooms.html for all rooms when I click on Book now I receive this message in modal Box: Null quantity.

When does this message occur?. How to solve it without rebooting put the demo website database? because I met the same bug in my local installation and I dropped the application (in production I should not reset each time the base of the site ... :) )

wdammak commented 5 years ago

This error is being handled in the CartController.php file and you have this: hotelcommerce/controllers/front/CartController.php

/**
  • This process add or update a product in the cart / protected function processChangeProductInCart() { $mode = (Tools::getIsset('update') && $this->id_product) ? 'update' : 'add'; $date_from = Tools::getValue('dateFrom'); $date_to = Tools::getValue('dateTo'); $date_from = date("Y-m-d", strtotime($date_from)); $date_to = date("Y-m-d", strtotime($date_to)); $id_cart = $this->context->cart->id; $id_guest = $this->context->cart->id_guest; /
  • By Webkul
  • This code is to check available quantity of Room before adding it to cart. / if (Module::isInstalled('hotelreservationsystem') && Module::isEnabled('hotelreservationsystem')) { require_once _PS_MODULEDIR.'hotelreservationsystem/define.php'; $obj_booking_detail = new HotelBookingDetail(); $num_days = $obj_booking_detail->getNumberOfDays($date_from, $date_to); $req_rm = $this->qty; $this->qty = $this->qty (int) $num_days; $obj_room_type = new HotelRoomType(); $room_info_by_id_product = $obj_room_type->getRoomTypeInfoByIdProduct($this->id_product); if ($room_info_by_id_product) { $id_hotel = $room_info_by_id_product['id_hotel']; if ($id_hotel) { /Check Order restrict condition before adding in to cart/ $max_order_date = HotelOrderRestrictDate::getMaxOrderDate($id_hotel); if ($max_order_date) { $max_order_date = date('Y-m-d', strtotime($max_order_date)); if ($max_order_date < $date_from || $max_order_date < $date_to) { $this->errors[] = Tools::displayError('You can\'t Book room after date '.$max_order_date); } } /END/ $obj_booking_dtl = new HotelBookingDetail(); $hotel_room_data = $obj_booking_dtl->DataForFrontSearch($date_from, $date_to, $id_hotel, $this->id_product, 1, 0, 0, -1, 0, 0, $id_cart, $id_guest); $total_available_rooms = $hotel_room_data['stats']['num_avail']; if ($total_available_rooms < $req_rm) { die(Tools::jsonEncode(array('status' => 'unavailable_quantity', 'avail_rooms' => $total_available_rooms))); } } else { die(Tools::jsonEncode(array('status' => 'failed3'))); } } else { die(Tools::jsonEncode(array('status' => 'failed4'))); } } if ($this->qty == 0) { $this->errors[] = Tools::displayError('Null quantity.', !Tools::getValue('ajax')); } elseif (!$this->id_product) { $this->errors[] = Tools::displayError('Product not found', !Tools::getValue('ajax')); }

Witch means you are trying to add a product with a null qty. So I have Number of rooms at 1 and 5 Room (s) Left! This is a bug from somewhere ?! Or is the quantity of the product incorrectly calculated?

wdammak commented 5 years ago

A correction without looking for the real cause why the quantity is null: Before

$this->qty = $this->qty * (int) $num_days;

$this->qty = ($this->qty == 0) ? 1 : $this->qty; $num_days = ((int) $num_days == 0) ? 1 : (int) $num_days;

sumitwebkul commented 5 years ago

@wdammak Can you explain here the scenario in full details? like what date range you chose etc.. Because we are unable to reproduce the issue. If once we reproduce the issue, then it will be easy for us to find the cause of the issue. Thanks.

wdammak commented 5 years ago

It's already notified a few months ago ... https://github.com/webkul/hotelcommerce/issues/66

Exactly this bug is random! sometimes happens on your site and other times not ... I imagine he had to ajax. My proposal is preventive and has nothing major change (it's a test reinforcement of the inputs)

sumitwebkul commented 5 years ago

@wdammak Ok, Let us check the issue in deep once. So that we can find the exact solution for this.

wdammak commented 5 years ago

@sumitwebkul ok as u like thx!

sumitwebkul commented 5 years ago

@wdammak Thanks for your PR. We are reviewing it at our end and will update soon.

wdammak commented 5 years ago

@sumitwebkul

It seems that I found how to reproduce this bug!

https://demo.qloapps.com/home/8-super-delux-rooms.html?date_from=2019-08-25&date_to=2019-08-25

When the date_from and the date_to passed in parameter are identical they are accepted in the entries (Check In Date & Check Out Date) and once we click on Book now this modal box "Null quantity." appear!

This is normal because in your calculations you made qty = date_to-date_from = 25-25 == 0 => qty = 0 => Null quantity.

So, it is necessary in this case to increment automatically the date_to when date_from == date_to or to add a condition in the case the two dates are identical: $qty = (date_to == date_from)? 1: (date_to-date_from);

This bug can also happen when a customer starts filling out their form just before midnight with the current day's date and clicks the book now button after midnight.

It would also be better to replace this information message "Null quantity." by another more explicit message (eg "Please check the validation of your Check In Date & Check Out Date")

sumitwebkul commented 5 years ago

@wdammak Thanks for your help to reproduce the issue. And thanks for your code change suggestions. We are reviewing it at our end and will update soon.

wdammak commented 5 years ago

better fix bug https://github.com/webkul/hotelcommerce/pull/76

sumitwebkul commented 5 years ago

@wdammak We will fix it soon. And surely it will be resolved in the next version. We are checking your PR. But we have to check all the occurring reasons for the bug and best resolution. SO please wait for the soon update.

wdammak commented 5 years ago

@sumitwebkul thx!