Skip to content

Commit

Permalink
Fix room add issue
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek-webkul committed Feb 28, 2023
1 parent 7f7122d commit f400ce0
Showing 1 changed file with 34 additions and 30 deletions.
64 changes: 34 additions & 30 deletions controllers/admin/AdminOrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2695,10 +2695,6 @@ public function ajaxProcessAddProductOnOrder()
$this->context->cart = $cart;
$this->context->customer = new Customer($order->id_customer);

if ($order->with_occupancy) {
$objRoomType = new HotelRoomType();
$roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($id_product);
}
/*By Webkul to make entries in HotelCartBookingData */
$hotel_room_info_arr = $hotel_room_data['rm_data'][$idProduct]['data']['available'];
$chkQty = 0;
Expand All @@ -2724,8 +2720,8 @@ public function ajaxProcessAddProductOnOrder()
$objCartBookingData->children = $room_occupancy['children'];
$objCartBookingData->child_ages = $room_occupancy['children'] ? json_encode($room_occupancy['child_ages']) : json_encode(array());
} else {
$objCartBookingData->adults = $roomTypeInfo['adults'];
$objCartBookingData->children = $roomTypeInfo['children'];
$objCartBookingData->adults = $room_info_by_id_product['adults'];
$objCartBookingData->children = $room_info_by_id_product['children'];
$objCartBookingData->child_ages = json_encode(array());
}
$objCartBookingData->save();
Expand Down Expand Up @@ -3247,10 +3243,12 @@ public function ajaxProcessEditRoomOnOrder()
$product_quantity = (int) $obj_booking_detail->getNumberOfDays($new_date_from, $new_date_to);
$old_product_quantity = (int) $obj_booking_detail->getNumberOfDays($old_date_from, $old_date_to);
$qty_diff = $product_quantity - $old_product_quantity;
$occupancy = array_shift(Tools::getValue('occupancy'));
$adults = $occupancy['adults'];
$children = $occupancy['children'];
$child_ages = $occupancy['child_ages'];
if ($order->with_occupancy) {
$occupancy = array_shift(Tools::getValue('occupancy'));
$adults = $occupancy['adults'];
$children = $occupancy['children'];
$child_ages = $occupancy['child_ages'];
}

/*By webkul to validate fields before deleting the cart and order data form the tables*/
if ($id_hotel == '') {
Expand Down Expand Up @@ -3308,30 +3306,36 @@ public function ajaxProcessEditRoomOnOrder()
'result' => false,
'error' => Tools::displayError('Invalid quantity.'),
)));
} elseif (!isset($adults) || !$adults || !Validate::isUnsignedInt($adults)) {
die(json_encode(array(
'result' => false,
'error' => Tools::displayError('Invalid number of adults.'),
)));
} elseif (!Validate::isUnsignedInt($children)) {
die(json_encode(array(
'result' => false,
'error' => Tools::displayError('Invalid number of children.'),
)));
}
if ($children > 0) {
if (!isset($child_ages) || ($children != count($child_ages))) {

// validations if order is with occupancy
if ($order->with_occupancy) {
if (!isset($adults) || !$adults || !Validate::isUnsignedInt($adults)) {
die(json_encode(array(
'result' => false,
'error' => Tools::displayError('Please provide all children age.'),
'error' => Tools::displayError('Invalid number of adults.'),
)));
} else {
foreach($child_ages as $childAge) {
if (!Validate::isUnsignedInt($childAge)) {
die(json_encode(array(
'result' => false,
'error' => Tools::displayError('Invalid children age.'),
)));
} elseif (!Validate::isUnsignedInt($children)) {
die(json_encode(array(
'result' => false,
'error' => Tools::displayError('Invalid number of children.'),
)));
}

if ($children > 0) {
if (!isset($child_ages) || ($children != count($child_ages))) {
die(json_encode(array(
'result' => false,
'error' => Tools::displayError('Please provide all children age.'),
)));
} else {
foreach($child_ages as $childAge) {
if (!Validate::isUnsignedInt($childAge)) {
die(json_encode(array(
'result' => false,
'error' => Tools::displayError('Invalid children age.'),
)));
}
}
}
}
Expand Down

0 comments on commit f400ce0

Please sign in to comment.