From 935eb16d099733440f0e5215c3f4de19ae4c87e1 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 20 May 2025 12:24:25 +0530 Subject: [PATCH] Fixed: issues related to services having per day price type --- .../admin/AdminOrderPreferencesController.php | 2 +- .../classes/HotelCartBookingData.php | 11 ++--- .../classes/ServiceProductCartDetail.php | 40 ++++++++++--------- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/controllers/admin/AdminOrderPreferencesController.php b/controllers/admin/AdminOrderPreferencesController.php index d9254c35a..604eabe1f 100644 --- a/controllers/admin/AdminOrderPreferencesController.php +++ b/controllers/admin/AdminOrderPreferencesController.php @@ -311,7 +311,7 @@ class AdminOrderPreferencesControllerCore extends AdminController ), ); - if (Hook::exec('actionEnableStandartProductConfig') || _PS_MODE_DEV_) { + if (Hook::exec('actionEnableStandartProductConfig')) { $addressPrefrenceTypes = array( array( 'value' => Product::STANDARD_PRODUCT_ADDRESS_PREFERENCE_CUSTOMER, diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 753e14b31..3b6aff7ef 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -374,7 +374,6 @@ class HotelCartBookingData extends ObjectModel )) { $numRooms = count($cartBookingInfo); if ($updPsCart) { - $objBookingDetail = new HotelBookingDetail(); if (isset(Context::getContext()->controller->controller_type)) { $controllerType = Context::getContext()->controller->controller_type; } else { @@ -385,7 +384,7 @@ class HotelCartBookingData extends ObjectModel $idPsCart = $bookingRow['id_cart']; $idPsProduct = $bookingRow['id_product']; $objCart = new Cart($idPsCart); - $updQty = $objBookingDetail->getNumberOfDays($bookingRow['date_from'], $bookingRow['date_to']); + $updQty = HotelHelper::getNumberOfDays($bookingRow['date_from'], $bookingRow['date_to']); // remove service product for this room $objServiceProductCartDetail->removeServiceProductByIdHtlCartBooking($bookingRow['id']); // if room type is deleting from admin then reduce product cart quantity by updating directly table @@ -724,8 +723,7 @@ class HotelCartBookingData extends ObjectModel $num_rm = Db::getInstance()->NumRows(); - $obj_htl_bk_dtl = new HotelBookingDetail(); - $num_days = $obj_htl_bk_dtl->getNumberOfDays($date_from, $date_to); + $num_days = HotelHelper::getNumberOfDays($date_from, $date_to); $qty = (int) $num_rm * (int) $num_days; if ($qty) { @@ -1503,7 +1501,6 @@ class HotelCartBookingData extends ObjectModel $price_tax = HotelBookingDetail::useTax(); // create needed objects $objCartBooking = new self(); - $objBookingDetail = new HotelBookingDetail(); $objRoomType = new HotelRoomType(); $objHotelBranch = new HotelBranchInformation(); $objHtlFeatures = new HotelFeatures(); @@ -1634,7 +1631,7 @@ class HotelCartBookingData extends ObjectModel $totalAdditionalServicePrice = $demandPrice + $serviceProductPrice; if (isset($cartHotelData[$prodKey]['date_diff'][$dateJoin])) { - $numDays = $objBookingDetail->getNumberOfDays($data_v['date_from'], $data_v['date_to']); + $numDays = HotelHelper::getNumberOfDays($data_v['date_from'], $data_v['date_to']); $cartHotelData[$prodKey]['date_diff'][$dateJoin]['demand_price'] += $totalAdditionalServicePrice; $cartHotelData[$prodKey]['date_diff'][$dateJoin]['num_rm'] += 1; $cartHotelData[$prodKey]['date_diff'][$dateJoin]['num_days'] = $numDays; @@ -1691,7 +1688,7 @@ class HotelCartBookingData extends ObjectModel $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']); + $numDays = HotelHelper::getNumberOfDays($data_v['date_from'], $data_v['date_to']); $cartHotelData[$prodKey]['date_diff'][$dateJoin]['num_rm'] = 1; $cartHotelData[$prodKey]['date_diff'][$dateJoin]['data_form'] = date( 'Y-m-d H:i:s', diff --git a/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php index ebe77d57e..67d7d2b11 100644 --- a/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php @@ -166,7 +166,7 @@ class ServiceProductCartDetail extends ObjectModel $language = new Language($idLang); } - $sql = 'SELECT spc.*, p.`selling_preference_type`, p.`price_calculation_method`, hcbd.`id_product` as `id_product_room_type`'; + $sql = 'SELECT spc.*, p.`selling_preference_type`, hcbd.`date_from`, hcbd.`date_to`, p.`price_calculation_method`, hcbd.`id_product` as `id_product_room_type`'; if (!$getTotalPrice) { $sql .= ', hbil.`hotel_name` '; } @@ -219,6 +219,7 @@ class ServiceProductCartDetail extends ObjectModel $selectedProducts = array(); $objServiceProductOption = new ServiceProductOption(); if ($serviceProducts = Db::getInstance()->executeS($sql)) { + $context = Context::getContext(); foreach ($serviceProducts as $product) { $objProduct = new Product($product['id_product'], false, $language->id); if (!$objProduct->booking_product) { @@ -231,12 +232,19 @@ class ServiceProductCartDetail extends ObjectModel $product['id_product_room_type'], $useTax, $qty, - null, - null, + $product['date_from'], + $product['date_to'], $idCart ); } else { - $context = Context::getContext(); + $numDays = 1; + // If price type is per day but the dates are not valid. + if (($objProduct->price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY) + && (!$numDays = HotelHelper::getNumberOfDays($product['date_from'], $product['date_to'])) + ) { + $numDays = 1; + } + $priceTaxIncl = Product::getServiceProductPrice( $objProduct->id, $product['id_product_option'], @@ -244,10 +252,10 @@ class ServiceProductCartDetail extends ObjectModel $product['id_product_room_type'], true, 1, - null, - null, + $product['date_from'], + $product['date_to'], $idCart - ); + )/$numDays; $priceTaxExcl = Product::getServiceProductPrice( $objProduct->id, $product['id_product_option'], @@ -255,10 +263,10 @@ class ServiceProductCartDetail extends ObjectModel $product['id_product_room_type'], false, 1, - null, - null, + $product['date_from'], + $product['date_to'], $idCart - ); + )/$numDays; $optionDetails = false; if (ServiceProductOption::productHasOptions($product['id_product'])) { @@ -298,8 +306,8 @@ class ServiceProductCartDetail extends ObjectModel 'unit_price_tax_incl' => $priceTaxIncl, 'unit_price_tax_excl' => $priceTaxExcl, 'quantity' => $product['quantity'], - 'total_price_tax_incl' => $priceTaxIncl * (int)$product['quantity'], - 'total_price_tax_excl' => $priceTaxExcl * (int)$product['quantity'], + 'total_price_tax_incl' => $priceTaxIncl * (int)$product['quantity'] * $numDays, + 'total_price_tax_excl' => $priceTaxExcl * (int)$product['quantity'] * $numDays, 'cover_img' => $coverImg, 'price_calculation_method' => $product['price_calculation_method'], ); @@ -309,7 +317,7 @@ class ServiceProductCartDetail extends ObjectModel $productInfo['date_from'] = $objHotelCartBooking->date_from; $productInfo['date_to'] = $objHotelCartBooking->date_to; $productInfo['id_room_type_hotel'] = $objHotelCartBooking->id_hotel; - $productInfo['id_room_type'] = $objHotelCartBooking->id_hotel; + $productInfo['id_room_type'] = $objHotelCartBooking->id_product; $productInfo['id_room'] = $objHotelCartBooking->id_room; } else { $productInfo['date_from'] = $product['date_from'] = ''; @@ -405,12 +413,6 @@ class ServiceProductCartDetail extends ObjectModel $objServiceProductCartDetail->id_product_option = $idProductOption; } - if ($idHtlCartData && Product::getProductPriceCalculation($idProduct) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $objHotelCartBookingData = new HotelCartBookingData($idHtlCartData); - $numdays = HotelHelper::getNumberOfDays($objHotelCartBookingData->date_from, $objHotelCartBookingData->date_to); - $quantity *= $numdays; - } - $objServiceProductCartDetail->quantity += $quantity; if ($objServiceProductCartDetail->save()) { $objCart = new Cart($idCart);