From dc0de8ecf565115c374856c0b4b99e8dc055c1f7 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Mon, 9 Sep 2024 11:33:37 +0530 Subject: [PATCH 1/7] Fixed: Invalid service prices when miltiple rooms are added in cart --- .../classes/HotelRoomTypeFeaturePricing.php | 6 ++++-- .../classes/RoomTypeServiceProduct.php | 20 +++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index de0131c57..a89cf79f9 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -726,7 +726,8 @@ public static function getRoomTypeTotalPrice( true, $id_cart, $id_guest, - $use_reduc + $use_reduc, + $id_room )) { foreach($servicesWithTax as $service) { $totalPrice['total_price_tax_incl'] += $service['price']; @@ -740,7 +741,8 @@ public static function getRoomTypeTotalPrice( false, $id_cart, $id_guest, - $use_reduc + $use_reduc, + $id_room )) { foreach($servicesWithoutTax as $service) { $totalPrice['total_price_tax_excl'] += $service['price']; diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php index 90c3b85e0..615d0b585 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php @@ -135,14 +135,30 @@ public function isRoomTypeLinkedWithProduct($idProductRoomType, $idServiceProduc return Db::getInstance()->getValue($sql); } - public static function getAutoAddServices($idProduct, $dateFrom = null, $dateTo = null, $priceAdditionType = null, $useTax = null, $idCart = 0, $idGuest = 0, $use_reduc = 1) - { + public static function getAutoAddServices($idProduct, + $dateFrom = null, + $dateTo = null, + $priceAdditionType = null, + $useTax = null, + $idCart = 0, + $idGuest = 0, + $use_reduc = 1, + $idRoom = 0 + ) { if (Product::isBookingProduct($idProduct)) { $sql = 'SELECT p.`id_product` FROM `'._DB_PREFIX_.'htl_room_type_service_product` rsp INNER JOIN `'._DB_PREFIX_.'product` p ON (rsp.`id_product` = p.`id_product` AND p.`auto_add_to_cart` = 1)'; if ($idCart) { $sql .= ' INNER JOIN `'._DB_PREFIX_.'htl_room_type_service_product_cart_detail` spcd ON (rsp.`id_product` = spcd.`id_product` AND spcd.`id_cart` = '.(int)$idCart.')'; + if ($dateFrom && $dateTo && $idRoom) { + $sql .= ' INNER JOIN `'._DB_PREFIX_.'htl_cart_booking_data` hcbd + ON (hcbd.`id` = spcd.`htl_cart_booking_id` + AND hcbd.`id_room` = '.(int)$idRoom.' + AND hcbd.`date_from` = \''.pSQL($dateFrom).'\' + AND hcbd.`date_to` = \''.pSQL($dateTo).'\' + )'; + } } $sql .= ' WHERE p.`active` = 1 AND `id_element` = '.(int)$idProduct.' AND `element_type` = '.self::WK_ELEMENT_TYPE_ROOM_TYPE; if (!is_null($priceAdditionType)) { From 4988194e11e3182aa1408f914f5d513d2ed3f516 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Mon, 9 Sep 2024 17:17:07 +0530 Subject: [PATCH 2/7] Fixed pricing issue in room auto add service --- .../classes/HotelCartBookingData.php | 6 ++--- .../classes/HotelRoomTypeFeaturePricing.php | 10 +++---- .../classes/RoomTypeServiceProduct.php | 27 +++++++++---------- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 29d5ddfa0..60eeff0af 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -1598,9 +1598,9 @@ public static function getHotelCartBookingData($detailed = 1) $amountWithoutAutoAdd = $roomTypeDateRangePriceWithoutAutoAdd['total_price_tax_incl']; $totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_incl']; } - $cartHotelData[$prodKey]['date_diff'][$dateJoin]['amount'] = $amount * $varQty; - $cartHotelData[$prodKey]['date_diff'][$dateJoin]['total_price_without_discount'] = $totalPriceWithoutDiscount * $varQty; - $cartHotelData[$prodKey]['date_diff'][$dateJoin]['amount_without_auto_add'] = $amountWithoutAutoAdd * $varQty; + $cartHotelData[$prodKey]['date_diff'][$dateJoin]['amount'] += $amount; + $cartHotelData[$prodKey]['date_diff'][$dateJoin]['total_price_without_discount'] += $totalPriceWithoutDiscount; + $cartHotelData[$prodKey]['date_diff'][$dateJoin]['amount_without_auto_add'] += $amountWithoutAutoAdd; } else { $cartHotelData[$prodKey]['date_diff'][$dateJoin]['demand_price'] = $totalAdditionalServicePrice; $numDays = $objBookingDetail->getNumberOfDays($data_v['date_from'], $data_v['date_to']); diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index a89cf79f9..e2bb55040 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -725,9 +725,8 @@ public static function getRoomTypeTotalPrice( Product::PRICE_ADDITION_TYPE_WITH_ROOM, true, $id_cart, - $id_guest, - $use_reduc, - $id_room + $id_room, + $use_reduc )) { foreach($servicesWithTax as $service) { $totalPrice['total_price_tax_incl'] += $service['price']; @@ -740,9 +739,8 @@ public static function getRoomTypeTotalPrice( Product::PRICE_ADDITION_TYPE_WITH_ROOM, false, $id_cart, - $id_guest, - $use_reduc, - $id_room + $id_room, + $use_reduc )) { foreach($servicesWithoutTax as $service) { $totalPrice['total_price_tax_excl'] += $service['price']; diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php index 615d0b585..9e3b2410e 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php @@ -141,28 +141,27 @@ public static function getAutoAddServices($idProduct, $priceAdditionType = null, $useTax = null, $idCart = 0, - $idGuest = 0, - $use_reduc = 1, - $idRoom = 0 + $idRoom = 0, + $use_reduc = 1 ) { if (Product::isBookingProduct($idProduct)) { $sql = 'SELECT p.`id_product` FROM `'._DB_PREFIX_.'htl_room_type_service_product` rsp INNER JOIN `'._DB_PREFIX_.'product` p ON (rsp.`id_product` = p.`id_product` AND p.`auto_add_to_cart` = 1)'; - if ($idCart) { + if ($idCart || ($dateFrom && $dateTo) || $idRoom) { $sql .= ' INNER JOIN `'._DB_PREFIX_.'htl_room_type_service_product_cart_detail` spcd - ON (rsp.`id_product` = spcd.`id_product` AND spcd.`id_cart` = '.(int)$idCart.')'; - if ($dateFrom && $dateTo && $idRoom) { - $sql .= ' INNER JOIN `'._DB_PREFIX_.'htl_cart_booking_data` hcbd - ON (hcbd.`id` = spcd.`htl_cart_booking_id` - AND hcbd.`id_room` = '.(int)$idRoom.' - AND hcbd.`date_from` = \''.pSQL($dateFrom).'\' - AND hcbd.`date_to` = \''.pSQL($dateTo).'\' - )'; - } + ON (rsp.`id_product` = spcd.`id_product` AND spcd.`id_cart` = '.(int)$idCart.') + INNER JOIN `'._DB_PREFIX_.'htl_cart_booking_data` hcbd + ON (hcbd.`id` = spcd.`htl_cart_booking_id`)'; } $sql .= ' WHERE p.`active` = 1 AND `id_element` = '.(int)$idProduct.' AND `element_type` = '.self::WK_ELEMENT_TYPE_ROOM_TYPE; if (!is_null($priceAdditionType)) { - $sql .= ' AND p.`price_addition_type` = '.$priceAdditionType; + $sql .= ' AND p.`price_addition_type` = '.(int)$priceAdditionType; + } + if ($dateFrom && $dateTo) { + $sql .= ' AND hcbd.`date_from` = \''.pSQL($dateFrom).'\' AND hcbd.`date_to` = \''.pSQL($dateTo).'\''; + } + if ($idRoom) { + $sql .= ' AND hcbd.`id_room` = '.(int)$idRoom; } if ($services = Db::getInstance()->executeS($sql)) { $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); From 43cc7a8a1e66e30b71deaa7f5ec621d6dccddbeb Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Wed, 11 Sep 2024 13:10:25 +0530 Subject: [PATCH 3/7] update price calculation for service product --- .../classes/HotelRoomTypeFeaturePricing.php | 70 ++++++++++++------- .../classes/RoomTypeServiceProduct.php | 29 ++------ .../RoomTypeServiceProductCartDetail.php | 6 +- 3 files changed, 56 insertions(+), 49 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index a3c9d09cb..af66bf054 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -718,32 +718,54 @@ public static function getRoomTypeTotalPrice( } } if ($with_auto_room_services) { - if ($servicesWithTax = RoomTypeServiceProduct::getAutoAddServices( - $id_product, - $date_from, - $date_to, - Product::PRICE_ADDITION_TYPE_WITH_ROOM, - true, - $id_cart, - $id_room, - $use_reduc - )) { - foreach($servicesWithTax as $service) { - $totalPrice['total_price_tax_incl'] += Tools::processPriceRounding($service['price']); + if ($id_cart) { + $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail(); + if ($roomServicesServices = $objRoomTypeServiceProductCartDetail->getServiceProductsInCart( + $id_cart, + 0, + 0, + $id_product, + $date_from, + $date_to, + 0, + 0, + null, + null, + null, + null, + $id_room + )) { + $selectedServices = array_shift($roomServicesServices); } } - if ($servicesWithoutTax = RoomTypeServiceProduct::getAutoAddServices( - $id_product, - $date_from, - $date_to, - Product::PRICE_ADDITION_TYPE_WITH_ROOM, - false, - $id_cart, - $id_room, - $use_reduc - )) { - foreach($servicesWithoutTax as $service) { - $totalPrice['total_price_tax_excl'] += Tools::processPriceRounding($service['price']); + + if (isset($selectedServices)) { + $totalPrice['total_price_tax_incl'] += Tools::processPriceRounding($selectedServices['total_price_tax_incl']); + $totalPrice['total_price_tax_excl'] += Tools::processPriceRounding($selectedServices['total_price_tax_excl']); + } else { + if ($servicesWithTax = RoomTypeServiceProduct::getAutoAddServices( + $id_product, + $date_from, + $date_to, + Product::PRICE_ADDITION_TYPE_WITH_ROOM, + true, + $use_reduc + )) { + foreach($servicesWithTax as $service) { + $totalPrice['total_price_tax_incl'] += Tools::processPriceRounding($service['price']); + } + } + if ($servicesWithoutTax = RoomTypeServiceProduct::getAutoAddServices( + $id_product, + $date_from, + $date_to, + Product::PRICE_ADDITION_TYPE_WITH_ROOM, + false, + $use_reduc + )) { + foreach($servicesWithoutTax as $service) { + $totalPrice['total_price_tax_excl'] += Tools::processPriceRounding($service['price']); + } } } } diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php index 0b327b14d..7c80b17e1 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php @@ -135,33 +135,14 @@ public function isRoomTypeLinkedWithProduct($idProductRoomType, $idServiceProduc return Db::getInstance()->getValue($sql); } - public static function getAutoAddServices($idProduct, - $dateFrom = null, - $dateTo = null, - $priceAdditionType = null, - $useTax = null, - $idCart = 0, - $idRoom = 0, - $use_reduc = 1 - ) { + public static function getAutoAddServices($idProduct, $dateFrom = null, $dateTo = null, $priceAdditionType = null, $useTax = null, $use_reduc = 1) + { if (Product::isBookingProduct($idProduct)) { $sql = 'SELECT p.`id_product` FROM `'._DB_PREFIX_.'htl_room_type_service_product` rsp - INNER JOIN `'._DB_PREFIX_.'product` p ON (rsp.`id_product` = p.`id_product` AND p.`auto_add_to_cart` = 1)'; - if ($idCart || ($dateFrom && $dateTo) || $idRoom) { - $sql .= ' INNER JOIN `'._DB_PREFIX_.'htl_room_type_service_product_cart_detail` spcd - ON (rsp.`id_product` = spcd.`id_product` AND spcd.`id_cart` = '.(int)$idCart.') - INNER JOIN `'._DB_PREFIX_.'htl_cart_booking_data` hcbd - ON (hcbd.`id` = spcd.`htl_cart_booking_id`)'; - } - $sql .= ' WHERE p.`active` = 1 AND `id_element` = '.(int)$idProduct.' AND `element_type` = '.self::WK_ELEMENT_TYPE_ROOM_TYPE; + INNER JOIN `'._DB_PREFIX_.'product` p ON (rsp.`id_product` = p.`id_product` AND p.`auto_add_to_cart` = 1) + WHERE p.`active` = 1 AND `id_element` = '.(int)$idProduct.' AND `element_type` = '.self::WK_ELEMENT_TYPE_ROOM_TYPE; if (!is_null($priceAdditionType)) { - $sql .= ' AND p.`price_addition_type` = '.(int)$priceAdditionType; - } - if ($dateFrom && $dateTo) { - $sql .= ' AND hcbd.`date_from` = \''.pSQL($dateFrom).'\' AND hcbd.`date_to` = \''.pSQL($dateTo).'\''; - } - if ($idRoom) { - $sql .= ' AND hcbd.`id_room` = '.(int)$idRoom; + $sql .= ' AND p.`price_addition_type` = '.$priceAdditionType; } if ($services = Db::getInstance()->executeS($sql)) { $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php index 0690e7374..0267f2117 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php @@ -211,7 +211,8 @@ public function getServiceProductsInCart( $useTax = null, $autoAddToCart = 0, $id_address = null, - $priceAdditionType = null + $priceAdditionType = null, + $idRoom = 0 ) { if ($useTax === null) $useTax = Product::$_taxCalculationMethod == PS_TAX_EXC ? false : true; @@ -256,6 +257,9 @@ public function getServiceProductsInCart( if ($dateFrom && $dateTo) { $sql .= ' AND cbd.`date_from` = \''.pSQL($dateFrom).'\' AND cbd.`date_to` = \''.pSQL($dateTo).'\''; } + if ($idRoom) { + $sql .= ' AND cbd.`id_room`='.(int) $idRoom; + } if ($htlCartBookingId) { $sql .= ' AND cbd.`id`='.(int) $htlCartBookingId; } From 0abba5721b1d3e00a6c7db012b86331e8ec61861 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Wed, 11 Sep 2024 19:59:08 +0530 Subject: [PATCH 4/7] remove service that are disabled or deleted --- .../classes/HotelCartBookingData.php | 164 +++++++++--------- .../RoomTypeServiceProductCartDetail.php | 15 +- 2 files changed, 99 insertions(+), 80 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 30a0145ed..7b752ef39 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -955,14 +955,20 @@ public static function validateCartBookings() $errors[] = $objModule->l('No booking found in the cart.', 'HotelOrderRestrictDate'); } - // validate service products if not active not then remove from cart - if ($cartProducts = $context->cart->getProducts()) { - $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail(); - foreach ($cartProducts as $product) { - if (!$product['active'] && !$product['booking_product']) { - $serviceProducts = $objRoomTypeServiceProductCartDetail->getServiceProductsInCart($context->cart->id, $product['id_product']); - foreach ($serviceProducts as $serviceProduct) { - $objRoomTypeServiceProductCartDetail->removeServiceProductByIdHtlCartBooking($serviceProduct['htl_cart_booking_id']); + // validate service products if not active, deleted or not associated to a specific room type then remove from cart + $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail(); + $objRoomTypeServiceProduct = new RoomTypeServiceProduct(); + if ($serviceProducts = $objRoomTypeServiceProductCartDetail->getAllServiceProduct($context->cart->id)) { + foreach ($serviceProducts as $service) { + if (!Validate::isLoadedObject($product = new Product($service['id_product']))) { + $objRoomTypeServiceProductCartDetail->removeServiceProductByIdHtlCartBooking($service['htl_cart_booking_id'], $service['id_product']); + } else { + if (!$product->active) { + $objRoomTypeServiceProductCartDetail->removeServiceProductByIdHtlCartBooking($service['htl_cart_booking_id'], $service['id_product']); + } else { + if (!$objRoomTypeServiceProduct->isRoomTypeLinkedWithProduct($service['id_product_room_type'], $service['id_product'])) { + $objRoomTypeServiceProductCartDetail->removeServiceProductByIdHtlCartBooking($service['htl_cart_booking_id'], $service['id_product']); + } } } } @@ -987,87 +993,89 @@ public static function validateCartBookings() $objHotelBookingDetail = new HotelBookingDetail(); foreach ($cartProducts as $product) { - if ($product['active']) { - if ($cartBookingData = $objHotelCartBookingData->getOnlyCartBookingData( - $context->cart->id, - $context->cart->id_guest, - $product['id_product'] - )) { - $cartData = array(); - foreach ($cartBookingData as $bookingData) { - $dateJoin = strtotime($bookingData['date_from']).strtotime($bookingData['date_to']); - $cartData[$dateJoin]['date_from'] = $bookingData['date_from']; - $cartData[$dateJoin]['date_to'] = $bookingData['date_to']; - $cartData[$dateJoin]['id_hotel'] = $bookingData['id_hotel']; - $cartData[$dateJoin]['id_rms'][] = $bookingData['id_room']; - } + if ($product['booking_product']) { + if ($product['active']) { + if ($cartBookingData = $objHotelCartBookingData->getOnlyCartBookingData( + $context->cart->id, + $context->cart->id_guest, + $product['id_product'] + )) { + $cartData = array(); + foreach ($cartBookingData as $bookingData) { + $dateJoin = strtotime($bookingData['date_from']).strtotime($bookingData['date_to']); + $cartData[$dateJoin]['date_from'] = $bookingData['date_from']; + $cartData[$dateJoin]['date_to'] = $bookingData['date_to']; + $cartData[$dateJoin]['id_hotel'] = $bookingData['id_hotel']; + $cartData[$dateJoin]['id_rms'][] = $bookingData['id_room']; + } - foreach ($cartData as $roomData) { - if (!$forAdminCart) { - if ($maxOrderDate = HotelOrderRestrictDate::getMaxOrderDate($roomData['id_hotel'])) { - if (strtotime('-1 day', strtotime($maxOrderDate)) < strtotime($roomData['date_from']) - || strtotime($maxOrderDate) < strtotime($roomData['date_to']) - ) { - $objHotelBranchInformation = new HotelBranchInformation( - $roomData['id_hotel'], - $context->language->id - ); - $errors[] = sprintf( - 'You can not book rooms for hotel \'%s\' after date %s. Please remove rooms from %s - %s to proceed.', - $objHotelBranchInformation->hotel_name, - Tools::displayDate($maxOrderDate), - Tools::displayDate($roomData['date_from']), - Tools::displayDate($roomData['date_to']) - ); + foreach ($cartData as $roomData) { + if (!$forAdminCart) { + if ($maxOrderDate = HotelOrderRestrictDate::getMaxOrderDate($roomData['id_hotel'])) { + if (strtotime('-1 day', strtotime($maxOrderDate)) < strtotime($roomData['date_from']) + || strtotime($maxOrderDate) < strtotime($roomData['date_to']) + ) { + $objHotelBranchInformation = new HotelBranchInformation( + $roomData['id_hotel'], + $context->language->id + ); + $errors[] = sprintf( + 'You can not book rooms for hotel \'%s\' after date %s. Please remove rooms from %s - %s to proceed.', + $objHotelBranchInformation->hotel_name, + Tools::displayDate($maxOrderDate), + Tools::displayDate($roomData['date_from']), + Tools::displayDate($roomData['date_to']) + ); + } } - } - $preparationTime = HotelOrderRestrictDate::getPreparationTime($roomData['id_hotel']); - if ($preparationTime !== false) { - $minOrderDate = date('Y-m-d', strtotime('+'. ($preparationTime) .' days')); - if (strtotime($minOrderDate) > strtotime($roomData['date_from']) - || strtotime($minOrderDate . ' +1 day')> strtotime($roomData['date_to']) - ) { - $objHotelBranchInformation = new HotelBranchInformation( - $roomData['id_hotel'], - $context->language->id - ); - $errors[] = sprintf( - 'You can not book rooms for hotel \'%s\' before date %s. Please remove rooms from %s - %s to proceed.', - $objHotelBranchInformation->hotel_name, - Tools::displayDate($minOrderDate), - Tools::displayDate($roomData['date_from']), - Tools::displayDate($roomData['date_to']) - ); + $preparationTime = HotelOrderRestrictDate::getPreparationTime($roomData['id_hotel']); + if ($preparationTime !== false) { + $minOrderDate = date('Y-m-d', strtotime('+'. ($preparationTime) .' days')); + if (strtotime($minOrderDate) > strtotime($roomData['date_from']) + || strtotime($minOrderDate . ' +1 day')> strtotime($roomData['date_to']) + ) { + $objHotelBranchInformation = new HotelBranchInformation( + $roomData['id_hotel'], + $context->language->id + ); + $errors[] = sprintf( + 'You can not book rooms for hotel \'%s\' before date %s. Please remove rooms from %s - %s to proceed.', + $objHotelBranchInformation->hotel_name, + Tools::displayDate($minOrderDate), + Tools::displayDate($roomData['date_from']), + Tools::displayDate($roomData['date_to']) + ); + } } } - } - $bookingParams = array( - 'date_from' => $roomData['date_from'], - 'date_to' => $roomData['date_to'], - 'hotel_id' => $roomData['id_hotel'], - 'id_room_type' => $product['id_product'], - 'only_search_data' => 1, - ); - $bookingSearchData = $objHotelBookingDetail->dataForFrontSearch($bookingParams); - $isRoomBooked = 0; - if (count($bookingSearchData['rm_data'][$product['id_product']]['data']['available']) < count($roomData['id_rms'])) { - foreach ($roomData['id_rms'] as $searchRoomData) { - if($isRoomBooked = $objHotelBookingDetail->chechRoomBooked($searchRoomData, $roomData['date_from'], $roomData['date_to'])){ - break; + $bookingParams = array( + 'date_from' => $roomData['date_from'], + 'date_to' => $roomData['date_to'], + 'hotel_id' => $roomData['id_hotel'], + 'id_room_type' => $product['id_product'], + 'only_search_data' => 1, + ); + $bookingSearchData = $objHotelBookingDetail->dataForFrontSearch($bookingParams); + $isRoomBooked = 0; + if (count($bookingSearchData['rm_data'][$product['id_product']]['data']['available']) < count($roomData['id_rms'])) { + foreach ($roomData['id_rms'] as $searchRoomData) { + if($isRoomBooked = $objHotelBookingDetail->chechRoomBooked($searchRoomData, $roomData['date_from'], $roomData['date_to'])){ + break; + } + } + if ($isRoomBooked) { + $errors[] = sprintf($objModule->l('The Room \'%s\' has been booked by another customer from \'%s\' to \'%s\' Please remove rooms from cart to proceed', 'HotelOrderRestrictDate'), $product['name'], date('d-m-Y', strtotime($roomData['date_from'])), date('d-m-Y', strtotime($roomData['date_to']))); + } else { + $errors[] = sprintf($objModule->l('The Room \'%s\' is no longer avalable from \'%s\' to \'%s\' Please remove rooms from cart to proceed', 'HotelOrderRestrictDate'), $product['name'], date('d-m-Y', strtotime($roomData['date_from'])), date('d-m-Y', strtotime($roomData['date_to']))); } - } - if ($isRoomBooked) { - $errors[] = sprintf($objModule->l('The Room \'%s\' has been booked by another customer from \'%s\' to \'%s\' Please remove rooms from cart to proceed', 'HotelOrderRestrictDate'), $product['name'], date('d-m-Y', strtotime($roomData['date_from'])), date('d-m-Y', strtotime($roomData['date_to']))); - } else { - $errors[] = sprintf($objModule->l('The Room \'%s\' is no longer avalable from \'%s\' to \'%s\' Please remove rooms from cart to proceed', 'HotelOrderRestrictDate'), $product['name'], date('d-m-Y', strtotime($roomData['date_from'])), date('d-m-Y', strtotime($roomData['date_to']))); } } } + } else { + $errors[] = $objModule->l('You can not book rooms from "', 'HotelOrderRestrictDate'). $product['name'] .$objModule->l('". Please remove rooms from "', 'HotelOrderRestrictDate'). $product['name'] . $objModule->l('" from cart to proceed.', 'HotelOrderRestrictDate'); } - } else { - $errors[] = $objModule->l('You can not book rooms from "', 'HotelOrderRestrictDate'). $product['name'] .$objModule->l('". Please remove rooms from "', 'HotelOrderRestrictDate'). $product['name'] . $objModule->l('" from cart to proceed.', 'HotelOrderRestrictDate'); } } } diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php index 0267f2117..9abe76f88 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php @@ -82,11 +82,12 @@ public function addServiceProductInCart( return false; } - public function removeServiceProductByIdHtlCartBooking($htlCartBookingId) + public function removeServiceProductByIdHtlCartBooking($htlCartBookingId, $idService = 0) { if ($stadardProductsData = Db::getInstance()->executeS( 'SELECT * FROM `' . _DB_PREFIX_ . 'htl_room_type_service_product_cart_detail` - WHERE `htl_cart_booking_id` = ' . (int)$htlCartBookingId + WHERE `htl_cart_booking_id` = ' . (int)$htlCartBookingId. + ($idService? ' AND `id_product` = '.(int)$idService : '') )) { foreach ($stadardProductsData as $product) { if (Validate::isLoadedObject( @@ -508,6 +509,16 @@ public function updateCartServiceProduct( return false; } + public function getAllServiceProduct($idCart) + { + return Db::getInstance()->executeS( + 'SELECT spcd.*, cbd.`id_product` as `id_product_room_type`, cbd.`id_room`, cbd.`id_hotel`, cbd.`date_from`, cbd.`date_to` FROM `' . _DB_PREFIX_ . 'htl_room_type_service_product_cart_detail` spcd + INNER JOIN `'._DB_PREFIX_.'htl_cart_booking_data` cbd + ON(spcd.`htl_cart_booking_id` = cbd.`id`) + WHERE spcd.`id_cart` = ' . (int)$idCart + ); + } + public static function validateServiceProductsInCart() { $context = Context::getContext(); From e74ef71c1966255446d91c6c09960fcc3a7c90e8 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Wed, 11 Sep 2024 20:28:57 +0530 Subject: [PATCH 5/7] fixed selected services not visible in serveices popup --- controllers/admin/AdminCartsController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index fb7ae888b..7a1d02d9f 100644 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -1122,7 +1122,10 @@ public function ajaxProcessGetRoomTypeCartDemands() 0, 0, $selectedRoomServiceProduct['id'], - ); + 0, + null, + null + )[$selectedRoomServiceProduct['id']]['selected_products_info']; } $this->context->smarty->assign(array( 'roomTypeServiceProducts' => $roomTypeServiceProducts, From 4419f0b56e1f45b09819797e08947772cf348c54 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Thu, 12 Sep 2024 10:50:12 +0530 Subject: [PATCH 6/7] Fixed: Services not showing selected after adding to cart --- controllers/admin/AdminCartsController.php | 10 ++-------- controllers/admin/AdminOrdersController.php | 13 +------------ controllers/front/OrderOpcController.php | 11 ++++------- .../classes/HotelCartBookingData.php | 11 ++++------- .../classes/RoomTypeServiceProductCartDetail.php | 5 +---- 5 files changed, 12 insertions(+), 38 deletions(-) diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index 7a1d02d9f..16070e286 100644 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -1114,18 +1114,12 @@ public function ajaxProcessGetRoomTypeCartDemands() $dateTo, $idRoom )) { - $selectedRoomServiceProduct['selected_service'] = $objRoomTypeServiceProductCartDetail->getServiceProductsInCart( - $idCart, - 0, - 0, - 0, - 0, - 0, + $selectedRoomServiceProduct['selected_service'] = $objRoomTypeServiceProductCartDetail->getRoomServiceProducts( $selectedRoomServiceProduct['id'], 0, null, null - )[$selectedRoomServiceProduct['id']]['selected_products_info']; + ); } $this->context->smarty->assign(array( 'roomTypeServiceProducts' => $roomTypeServiceProducts, diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index edf488755..30236549b 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -4514,18 +4514,7 @@ public function ajaxProcessAddProductOnOrder() $objRoomTypeServiceProduct = new RoomTypeServiceProduct(); $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail(); - if ($services = $objRoomTypeServiceProductCartDetail->getServiceProductsInCart( - $objCartBookingData->id_cart, - 0, - 0, - 0, - 0, - 0, - $objCartBookingData->id, - 0, - null, - 1 - )) { + if ($services = $objRoomTypeServiceProductCartDetail->getRoomServiceProducts($objCartBookingData->id, 0, null, 1)) { foreach ($services as $service) { $insertedServiceProductIdOrderDetail = $objBookingDetail->getLastInsertedServiceIdOrderDetail($order->id, $service['id_product']); $numDays = 1; diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 58988d92a..ff1248344 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -1032,14 +1032,11 @@ public function getRoomTypeBookingServices() $roomTypeServiceProducts = $objRoomTypeServiceProduct->getServiceProductsData($idProduct, 1, 0, true, 1); $cartRooms = $objCartBookingData->getHotelCartRoomsInfoByRoomType($this->context->cart->id, $idProduct,$dateFrom, $dateTo); foreach($cartRooms as &$room) { - $room['selected_service'] = $objRoomTypeServiceProductCartDetail->getServiceProductsInCart( - $room['id_cart'], + $room['selected_service'] = $objRoomTypeServiceProductCartDetail->getRoomServiceProducts( + $room['id'], 0, - 0, - 0, - 0, - 0, - $room['id'] + null, + null ); } $this->context->smarty->assign(array( diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 7b752ef39..1da8b668e 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -1178,14 +1178,11 @@ public function getCartFormatedBookinInfoByIdCart($id_cart) 2, null ); - $cart_detail_data[$key]['selected_services'] = $objRoomTypeServiceProductCartDetail->getServiceProductsInCart( - $value['id_cart'], - 0, - 0, - 0, - 0, + $cart_detail_data[$key]['selected_services'] = $objRoomTypeServiceProductCartDetail->getRoomServiceProducts( + $value['id'], 0, - $value['id'] + null, + null ); $cart_detail_data[$key]['additional_service_price'] = $objRoomTypeServiceProductCartDetail->getServiceProductsInCart( $id_cart, diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php index 9abe76f88..f638f295b 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php @@ -165,9 +165,6 @@ public function getServiceProductsTotalInCart( ); } - /** - * @deprecated since 1.6.1 use getServiceProductsInCart() instead - */ public function getRoomServiceProducts( $htlCartBookingId, $idLang = 0, @@ -193,7 +190,7 @@ public function getRoomServiceProducts( ); if (isset($selectedServiceProducts[$htlCartBookingId]['selected_products_info'])) { - return $selectedServiceProducts; + return $selectedServiceProducts[$htlCartBookingId]['selected_products_info']; } } From 629cffb6f45eb004107905bb6bee6b9cc4a9b54f Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Thu, 12 Sep 2024 12:00:39 +0530 Subject: [PATCH 7/7] Remove multiple rounding on same value --- .../classes/HotelRoomTypeFeaturePricing.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index af66bf054..6f6400f80 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -718,7 +718,7 @@ public static function getRoomTypeTotalPrice( } } if ($with_auto_room_services) { - if ($id_cart) { + if ($id_cart && $id_room) { $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail(); if ($roomServicesServices = $objRoomTypeServiceProductCartDetail->getServiceProductsInCart( $id_cart, @@ -740,8 +740,8 @@ public static function getRoomTypeTotalPrice( } if (isset($selectedServices)) { - $totalPrice['total_price_tax_incl'] += Tools::processPriceRounding($selectedServices['total_price_tax_incl']); - $totalPrice['total_price_tax_excl'] += Tools::processPriceRounding($selectedServices['total_price_tax_excl']); + $totalPrice['total_price_tax_incl'] += $selectedServices['total_price_tax_incl']; + $totalPrice['total_price_tax_excl'] += $selectedServices['total_price_tax_excl']; } else { if ($servicesWithTax = RoomTypeServiceProduct::getAutoAddServices( $id_product,