From f400ce0ce105f2a793f372455ff6fd4647fda1fb Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 28 Feb 2023 12:48:56 +0530 Subject: [PATCH] Fix room add issue --- controllers/admin/AdminOrdersController.php | 64 +++++++++++---------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index df4af2e8d..f928ddfc8 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -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; @@ -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(); @@ -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 == '') { @@ -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.'), + ))); + } } } }