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']; } diff --git a/classes/Product.php b/classes/Product.php index 6899144bb..54f9f21a4 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -3035,7 +3035,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 @@ -3204,7 +3205,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 @@ -3458,18 +3460,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); } @@ -3484,6 +3474,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) { diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index b0aa3a4f2..27e76f4fd 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -485,7 +485,7 @@ class AdminOrdersControllerCore extends AdminController $this->context->cart = $cart; $this->context->currency = new Currency((int)$cart->id_currency); $this->context->smarty->assign('info_icon_path', $this->context->link->getMediaLink(_MODULE_DIR_.'hotelreservationsystem/views/img/Slices/icon-info.svg')); - + $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( @@ -1069,25 +1069,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 9a61849de..9f9f4b51f 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -283,6 +283,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $totalPrice['total_price_tax_excl'] = 0; $featureImpactPriceTE = 0; $featureImpactPriceTI = 0; + $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,6 +319,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $id_guest, $id_room ))) { + if ($featurePrice['impact_type'] == self::IMPACT_TYPE_PERCENTAGE) { //percentage $featureImpactPriceTE = $productPriceTE * ($featurePrice['impact_value'] / 100); @@ -345,9 +347,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 { + + $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; } diff --git a/modules/hotelreservationsystem/define.php b/modules/hotelreservationsystem/define.php index dcb3b4426..1f6809c2b 100644 --- a/modules/hotelreservationsystem/define.php +++ b/modules/hotelreservationsystem/define.php @@ -61,6 +61,5 @@ require_once 'classes/ServiceProductOption.php'; require_once 'classes/HotelSettingsLink.php'; require_once 'classes/HotelBookingDocument.php'; - // Web services classes require_once 'classes/WebserviceSpecificManagementHotelAri.php';