From c72dbf376e4bb5c5b1aff203ab8b4aef935be7ca Mon Sep 17 00:00:00 2001 From: amit sharma Date: Tue, 28 Jul 2026 15:38:41 +0530 Subject: [PATCH 1/5] Fixed: Refactor group discount calculation to apply after advance price rules Co-authored-by: Name --- classes/Product.php | 55 ++++++++++++++----- controllers/admin/AdminOrdersController.php | 52 ++++++++++++------ .../classes/HotelRoomTypeFeaturePricing.php | 11 ++++ .../classes/RoomTypeServiceProductPrice.php | 3 +- 4 files changed, 89 insertions(+), 32 deletions(-) diff --git a/classes/Product.php b/classes/Product.php index fc962d3c0..afd481ed0 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -3033,7 +3033,8 @@ class ProductCore extends ObjectModel * @param null $specific_price_output If a specific price applies regarding the previous parameters, * this variable is filled with the corresponding SpecificPrice object * @param bool $with_ecotax Insert ecotax in price output. - * @param bool $use_group_reduction + * @param bool $use_group_reduction @deprecated no longer applied here; call + * Product::applyGroupDiscount() explicitly on your final total. * @param Context $context * @param bool $use_customer_price * @return float Product price @@ -3202,7 +3203,8 @@ class ProductCore extends ObjectModel * @param bool $with_ecotax insert ecotax in price output. * @param null $specific_price If a specific price applies regarding the previous parameters, * this variable is filled with the corresponding SpecificPrice object - * @param bool $use_group_reduction + * @param bool $use_group_reduction @deprecated no longer applied here; call + * Product::applyGroupDiscount() explicitly on your final total. * @param int $id_customer * @param bool $use_customer_price * @param int $id_cart @@ -3456,18 +3458,6 @@ class ProductCore extends ObjectModel $price -= $specific_price_reduction; } - // Group reduction - if ($use_group_reduction) { - $reduction_from_category = GroupReduction::getValueForProduct($id_product, $id_group); - if ($reduction_from_category !== false) { - $group_reduction = $price * (float)$reduction_from_category; - } else { // apply group reduction if there is no group reduction for this category - $group_reduction = (($reduc = Group::getReductionByIdGroup($id_group)) != 0) ? ($price * $reduc / 100) : 0; - } - - $price -= $group_reduction; - } - if ($only_reduc) { return Tools::ps_round($specific_price_reduction, $decimals); } @@ -3482,6 +3472,32 @@ class ProductCore extends ObjectModel return self::$_prices[$cache_id]; } + /** + * Applies the group discount to an already-computed price. + * @param float $price The price to discount (tax-incl. or tax-excl., either works). + * @param int $id_product + * @param int $id_group + * @param bool $use_group_reduction + * @return float + */ + public static function applyGroupDiscount($price, $id_product, $id_group, $use_group_reduction = true) + { + if (!$use_group_reduction) { + return $price; + } + + $reduction_from_category = GroupReduction::getValueForProduct($id_product, $id_group); + if ($reduction_from_category !== false) { + $group_reduction = $price * (float)$reduction_from_category; + } else { // apply group reduction if there is no group reduction for this category + $group_reduction = (($reduc = Group::getReductionByIdGroup($id_group)) != 0) ? ($price * $reduc / 100) : 0; + } + + $price -= $group_reduction; + + return $price < 0 ? 0 : $price; + } + public static function convertAndFormatPrice($price, $currency = false, ?Context $context = null) { if (!$context) { @@ -6871,6 +6887,15 @@ class ProductCore extends ObjectModel $price = $price * HotelHelper::getNumberOfDays($dateFrom, $dateTo); } - return $price * (int)$quantity; + $price = $price * (int)$quantity; + + if (!$specificPrice || $specificPrice['price'] < 0) { + if (!$idGroup || !Validate::isLoadedObject(new Group((int)$idGroup))) { + $idGroup = (int)Group::getCurrent()->id; + } + $price = Product::applyGroupDiscount($price, $idProduct, $idGroup); + } + return $price; + } } diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index bcbe5868c..3f9bbb216 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -437,7 +437,7 @@ class AdminOrdersControllerCore extends AdminController if (!$cart_order_exists) { $this->context->cart = $cart; $this->context->currency = new Currency((int)$cart->id_currency); - + $this->context->customer = new Customer((int)$cart->id_customer); // validate cart for removing invalid data from cart before new order creation // remove not linked services with room types from cart if not allowed to book them $this->errors = array_merge( @@ -999,25 +999,45 @@ class AdminOrdersControllerCore extends AdminController $objProduct = new Product(); $hotelServiceProducts = $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE); $roomTypeServiceProducts = $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE); - $serviceProducts = array_merge($roomTypeServiceProducts, $hotelServiceProducts); - } else { - $objRoomTypeServiceProduct = new RoomTypeServiceProduct(); - $serviceProducts = $objRoomTypeServiceProduct->getServiceProductsData($idProduct, 1, 0, false, 2, null); - } - - if ($serviceProducts) { - foreach ($serviceProducts as $key => $servProduct) { - $serviceProducts[$key]['price_tax_exc'] = $servProduct['price']; - if (isset($additionalServices[$productLineData['id']]) - && in_array($servProduct['id_product'], array_column($additionalServices[$productLineData['id']]['additional_services'], 'id_product')) - ) { - unset($serviceProducts[$key]); + if ($serviceProducts = array_merge($roomTypeServiceProducts, $hotelServiceProducts)) { + foreach ($serviceProducts as $key => $servProduct) { + if (!empty($additionalServices[$productLineData['id']]) + && in_array($servProduct['id_product'], array_column($additionalServices[$productLineData['id']]['additional_services'], 'id_product')) + ) { + unset($serviceProducts[$key]); + } else { + $numDays = 1; + if (Product::PRICE_CALCULATION_METHOD_PER_DAY == $servProduct['price_calculation_method']) { + $numDays = HotelHelper::getNumberOfDays($dateFrom, $dateTo); + } + $serviceProducts[$key]['price_tax_exc'] = Product::getServiceProductPrice( + $servProduct['id_product'], + 0, + 0, + $idProduct, + false, + 1, + $dateFrom, + $dateTo + )/$numDays; + } } } + } else { + $objRoomTypeServiceProduct = new RoomTypeServiceProduct(); + if ($serviceProducts = $objRoomTypeServiceProduct->getServiceProductsData($idProduct, 1, 0, false, 2, null)) { + foreach ($serviceProducts as $key => $servProduct) { + if (isset($additionalServices[$productLineData['id']]) + && in_array($servProduct['id_product'], array_column($additionalServices[$productLineData['id']]['additional_services'], 'id_product')) + ) { + unset($serviceProducts[$key]); + } + } - $smartyVars['serviceProducts'] = $serviceProducts; + } } - + + $smartyVars['serviceProducts'] = $serviceProducts; $objOrderReturn = new OrderReturn(); $refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($objOrder->id, 0, 1); $smartyVars['refundReqBookings'] = $refundReqBookings; diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index dd4f7da37..d730acf5e 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -282,6 +282,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $totalPrice['total_price_tax_excl'] = 0; $featureImpactPriceTE = 0; $featureImpactPriceTI = 0; + $isCartPriceOverridden = true; $productPriceTI = Product::getPriceStatic((int) $id_product, 1, 0, 6, null, 0, $use_reduc, 1, 0, null, null, null, $nothing, 1, 1, null, 1, 0, 0, $id_group); $productPriceTE = Product::getPriceStatic((int) $id_product, 0, 0, 6, null, 0, $use_reduc, 1, 0, null, null, null, $nothing, 1, 1, null, 1, 0, 0, $id_group); $id_address = HotelRoomType::getHotelIdAddressByIdProduct($id_product); @@ -317,6 +318,9 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $id_guest, $id_room ))) { + if ((int)$featurePrice['id_cart'] === 0) { + $isCartPriceOverridden = false; + } if ($featurePrice['impact_type'] == self::IMPACT_TYPE_PERCENTAGE) { //percentage $featureImpactPriceTE = $productPriceTE * ($featurePrice['impact_value'] / 100); @@ -347,6 +351,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $totalPrice['total_price_tax_incl'] += $priceWithFeatureTI; $totalPrice['total_price_tax_excl'] += $priceWithFeatureTE; } else { + $isCartPriceOverridden = false; $totalPrice['total_price_tax_incl'] += $productPriceTI; $totalPrice['total_price_tax_excl'] += $productPriceTE; } @@ -368,6 +373,12 @@ class HotelRoomTypeFeaturePricing extends ObjectModel 'occupancy' => $occupancy ) ); + + if (!$isCartPriceOverridden) { + $totalPrice['total_price_tax_incl'] = Product::applyGroupDiscount($totalPrice['total_price_tax_incl'], $id_product, $id_group); + $totalPrice['total_price_tax_excl'] = Product::applyGroupDiscount($totalPrice['total_price_tax_excl'], $id_product, $id_group); + } + if ($with_auto_room_services) { if ($id_cart && $id_room) { $objHotelCartBookingData = new HotelCartBookingData(); diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php index 133196573..9778a7f55 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php @@ -144,7 +144,8 @@ class RoomTypeServiceProductPrice extends ObjectModel $idHotelAddress ); - return $price * (int)$quantity; + $price = $price * (int)$quantity; + return Product::applyGroupDiscount($price, $idProduct, (int)Group::getCurrent()->id); } } From b9de6d3fbf3f92a60733a2c9e296b42bceab2714 Mon Sep 17 00:00:00 2001 From: aradhana kumari Date: Wed, 29 Jul 2026 19:21:21 +0530 Subject: [PATCH 2/5] Fixed: Combine/Compress JS (CCC) concatenates files without a statement separator, causing intermittent SyntaxError and breaking front-office scripts Co-authored-by: Name --- classes/Media.php | 1 + 1 file changed, 1 insertion(+) diff --git a/classes/Media.php b/classes/Media.php index 779d3f4bb..58feb76d8 100644 --- a/classes/Media.php +++ b/classes/Media.php @@ -737,6 +737,7 @@ class MediaCore } else { $content .= Media::packJS($tmp_content); } + $content .= ";\n"; } else { $compressed_js_files_not_found[] = $file_infos['path']; } From b6319da700f6ac03a2174d798e016d0456127bed Mon Sep 17 00:00:00 2001 From: amit sharma Date: Mon, 17 Aug 2026 15:05:25 +0530 Subject: [PATCH 3/5] Fixed: addressed Review Feedback Changes Co-authored-by: Name --- .../classes/HotelRoomTypeFeaturePricing.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index d730acf5e..9ffc64aef 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -282,7 +282,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $totalPrice['total_price_tax_excl'] = 0; $featureImpactPriceTE = 0; $featureImpactPriceTI = 0; - $isCartPriceOverridden = true; + $productPriceTI = Product::getPriceStatic((int) $id_product, 1, 0, 6, null, 0, $use_reduc, 1, 0, null, null, null, $nothing, 1, 1, null, 1, 0, 0, $id_group); $productPriceTE = Product::getPriceStatic((int) $id_product, 0, 0, 6, null, 0, $use_reduc, 1, 0, null, null, null, $nothing, 1, 1, null, 1, 0, 0, $id_group); $id_address = HotelRoomType::getHotelIdAddressByIdProduct($id_product); @@ -318,9 +318,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $id_guest, $id_room ))) { - if ((int)$featurePrice['id_cart'] === 0) { - $isCartPriceOverridden = false; - } + if ($featurePrice['impact_type'] == self::IMPACT_TYPE_PERCENTAGE) { //percentage $featureImpactPriceTE = $productPriceTE * ($featurePrice['impact_value'] / 100); @@ -348,10 +346,16 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $priceWithFeatureTI = 0; $priceWithFeatureTE = 0; } + if ((int)$featurePrice['id_cart'] == 0) { + $priceWithFeatureTI = Product::applyGroupDiscount($priceWithFeatureTI, $id_product, $id_group); + $priceWithFeatureTE = Product::applyGroupDiscount($priceWithFeatureTE, $id_product, $id_group); + } $totalPrice['total_price_tax_incl'] += $priceWithFeatureTI; $totalPrice['total_price_tax_excl'] += $priceWithFeatureTE; } else { - $isCartPriceOverridden = false; + + $productPriceTI = Product::applyGroupDiscount($productPriceTI, $id_product, $id_group); + $productPriceTE = Product::applyGroupDiscount($productPriceTE, $id_product, $id_group); $totalPrice['total_price_tax_incl'] += $productPriceTI; $totalPrice['total_price_tax_excl'] += $productPriceTE; } @@ -374,10 +378,6 @@ class HotelRoomTypeFeaturePricing extends ObjectModel ) ); - if (!$isCartPriceOverridden) { - $totalPrice['total_price_tax_incl'] = Product::applyGroupDiscount($totalPrice['total_price_tax_incl'], $id_product, $id_group); - $totalPrice['total_price_tax_excl'] = Product::applyGroupDiscount($totalPrice['total_price_tax_excl'], $id_product, $id_group); - } if ($with_auto_room_services) { if ($id_cart && $id_room) { From ef28409fb06344c6ed9b98a43cf933c053a60c61 Mon Sep 17 00:00:00 2001 From: amit sharma Date: Tue, 18 Aug 2026 11:54:16 +0530 Subject: [PATCH 4/5] Fixed: fix specific price calculation issue --- classes/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Product.php b/classes/Product.php index afd481ed0..36bf65ca8 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -6889,7 +6889,7 @@ class ProductCore extends ObjectModel $price = $price * (int)$quantity; - if (!$specificPrice || $specificPrice['price'] < 0) { + if (!$specificPrice || $specificPrice['id_cart'] == 0) { if (!$idGroup || !Validate::isLoadedObject(new Group((int)$idGroup))) { $idGroup = (int)Group::getCurrent()->id; } From d73f026306a90030eee74cdc1ec42ac70b92a652 Mon Sep 17 00:00:00 2001 From: amit sharma Date: Wed, 19 Aug 2026 10:22:42 +0530 Subject: [PATCH 5/5] Fixed : fix testing issue --- classes/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Product.php b/classes/Product.php index 36bf65ca8..6dd24ce58 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -6889,7 +6889,7 @@ class ProductCore extends ObjectModel $price = $price * (int)$quantity; - if (!$specificPrice || $specificPrice['id_cart'] == 0) { + if (!$specificPrice || ($specificPrice['id_cart'] == 0 && $specificPrice['id_htl_cart_booking'] == 0)) { if (!$idGroup || !Validate::isLoadedObject(new Group((int)$idGroup))) { $idGroup = (int)Group::getCurrent()->id; }