Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix room add/edit issue on order from back office #568

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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