From 898477c76e764b82d4a272874ff2d277beaf8eee Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 16 Aug 2024 15:32:42 +0530 Subject: [PATCH] Update: centralized the room price calculation process, updated function get getRoomTypeTotalPrice() --- controllers/front/ProductController.php | 19 ++++++++++-- .../classes/HotelCartBookingData.php | 30 +++++++++++++++++-- .../classes/HotelRoomTypeFeaturePricing.php | 11 +++---- modules/wkhotelroom/wkhotelroom.php | 24 +++++++++++++-- 4 files changed, 71 insertions(+), 13 deletions(-) diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index fbaf318ec..404742796 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -653,7 +653,18 @@ class ProductControllerCore extends FrontController // calculate room type price first $useTax = HotelBookingDetail::useTax(); $totalPrice = 0; - $productPriceWithoutReduction = $objProduct->getPriceWithoutReduct(!$useTax); + $priceWithoutDiscount = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $idProduct, + $dateFrom, + $dateTo, + 0, + 0, + 0, + 0, + 0, + 1, + 0 + ); $roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( $idProduct, $dateFrom, @@ -669,6 +680,8 @@ class ProductControllerCore extends FrontController true ); $roomTypeDateRangePrice = $roomTypeDateRangePrice['total_price_tax_incl']; + $totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_incl']; + } else { $featurePrice = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay( $idProduct, @@ -677,9 +690,10 @@ class ProductControllerCore extends FrontController false ); $roomTypeDateRangePrice = $roomTypeDateRangePrice['total_price_tax_excl']; + $totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_excl']; } - $featurePriceDiff = (float) ($productPriceWithoutReduction - $featurePrice); + $totalPriceWithoutDiscount *= $quantity; $totalRoomPrice = $roomTypeDateRangePrice * $quantity; // calculate demand price now $demandsPricePerRoom = 0; @@ -767,7 +781,6 @@ class ProductControllerCore extends FrontController $demandsPrice = $demandsPricePerRoom * $quantity; // calculate total price $totalPrice = $totalRoomPrice + $demandsPrice; - $totalPriceWithoutDiscount = $objProduct->getPriceWithoutReduct(!$useTax, false, 6, 1) * $numDays * $quantity; // send occupancy information searched by the user if ($occupancy && is_array($occupancy)) { $smartyVars['occupancies'] = $occupancy; diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 3e147a59a..1ea42986b 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -1574,13 +1574,26 @@ class HotelCartBookingData extends ObjectModel $data_v['id_room'], 0 ); - $totalPriceWithoutDiscount = $objProduct->getPriceWithoutReduct(!$price_tax, false, 6, 1) * $numDays; + $priceWithoutDiscount = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $product['id_product'], + $data_v['date_from'], + $data_v['date_to'], + 0, + 0, + $context->cart->id, + $context->cart->id_guest, + $data_v['id_room'], + 1, + 0 + ); if (!$price_tax) { $amount = $roomTypeDateRangePrice['total_price_tax_excl']; $amountWithoutAutoAdd = $roomTypeDateRangePriceWithoutAutoAdd['total_price_tax_excl']; + $totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_excl']; } else { $amount = $roomTypeDateRangePrice['total_price_tax_incl']; $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; @@ -1623,13 +1636,26 @@ class HotelCartBookingData extends ObjectModel $data_v['id_room'], 0 ); - $totalPriceWithoutDiscount = $objProduct->getPriceWithoutReduct(!$price_tax, false, 6, 1) * $numDays; + $priceWithoutDiscount = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $product['id_product'], + $data_v['date_from'], + $data_v['date_to'], + 0, + 0, + $context->cart->id, + $context->cart->id_guest, + $data_v['id_room'], + 1, + 0 + ); if (!$price_tax) { $amount = $roomTypeDateRangePrice['total_price_tax_excl']; $amountWithoutAutoAdd = $roomTypeDateRangePriceWithoutAutoAdd['total_price_tax_excl']; + $totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_excl']; } else { $amount = $roomTypeDateRangePrice['total_price_tax_incl']; $amountWithoutAutoAdd = $roomTypeDateRangePriceWithoutAutoAdd['total_price_tax_incl']; + $totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_incl']; } $cartHotelData[$prodKey]['date_diff'][$dateJoin]['amount'] = $amount; $cartHotelData[$prodKey]['date_diff'][$dateJoin]['amount_without_auto_add'] = $amountWithoutAutoAdd; diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index c4b0a6bc3..e4a9f4fe3 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -647,15 +647,16 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $id_cart = 0, $id_guest = 0, $id_room = 0, - $with_auto_room_services = 1 + $with_auto_room_services = 1, + $usereduc = 1 ) { $totalPrice = array(); $totalPrice['total_price_tax_incl'] = 0; $totalPrice['total_price_tax_excl'] = 0; $featureImpactPriceTE = 0; $featureImpactPriceTI = 0; - $productPriceTI = Product::getPriceStatic((int) $id_product, true); - $productPriceTE = Product::getPriceStatic((int) $id_product, false); + $productPriceTI = Product::getPriceStatic((int) $id_product, true, false, 6, null, false, $usereduc); + $productPriceTE = Product::getPriceStatic((int) $id_product, false, false, 6, null, false, $usereduc); if ($productPriceTE) { $taxRate = (($productPriceTI-$productPriceTE)/$productPriceTE)*100; } else { @@ -678,14 +679,14 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $date_from = date('Y-m-d', strtotime($date_from)); $date_to = date('Y-m-d', strtotime($date_to)); for($currentDate = $date_from; $currentDate < $date_to; $currentDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate)))) { - if ($featurePrice = $hotelCartBookingData->getProductFeaturePricePlanByDateByPriority( + if ($usereduc && ($featurePrice = $hotelCartBookingData->getProductFeaturePricePlanByDateByPriority( $id_product, $currentDate, $id_group, $id_cart, $id_guest, $id_room - )) { + ))) { if ($featurePrice['impact_type'] == self::IMPACT_TYPE_PERCENTAGE) { //percentage $featureImpactPriceTE = $productPriceTE * ($featurePrice['impact_value'] / 100); diff --git a/modules/wkhotelroom/wkhotelroom.php b/modules/wkhotelroom/wkhotelroom.php index 2df6101fd..a625ee434 100644 --- a/modules/wkhotelroom/wkhotelroom.php +++ b/modules/wkhotelroom/wkhotelroom.php @@ -65,14 +65,32 @@ class WkHotelRoom extends Module ImageType::getFormatedName('large') ); } - $productPriceWithoutReduction = $product->getPriceWithoutReduct(!$useTax, false, 6, 1); + $productPriceWithoutReduction = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $idProduct, + $dateFrom, + $dateTo, + $useTax, + 0, + 0, + 0, + 0, + 1, + 0 + ); + + if ($useTax) { + $priceWithoutReduction = $productPriceWithoutReduction['total_price_tax_incl']; + } else { + $priceWithoutReduction = $productPriceWithoutReduction['total_price_tax_excl']; + } + $product_price = Product::getPriceStatic($idProduct, $useTax); $htlRoom['image'] = $prodImg; $htlRoom['description'] = $product->description_short; $htlRoom['name'] = $product->name; $htlRoom['show_price'] = $product->show_price; $htlRoom['price'] = $product_price; - $htlRoom['price_without_reduction'] = $productPriceWithoutReduction; + $htlRoom['price_without_reduction'] = $priceWithoutReduction; $featurePrice = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay( $idProduct, $dateFrom, @@ -220,7 +238,7 @@ class WkHotelRoom extends Module } return true; } - + public function deleteConfigKeys() { $configVars = array(