diff --git a/admin/themes/default/template/controllers/normal_products/prices.tpl b/admin/themes/default/template/controllers/normal_products/prices.tpl index bae5d1211..6d315a307 100644 --- a/admin/themes/default/template/controllers/normal_products/prices.tpl +++ b/admin/themes/default/template/controllers/normal_products/prices.tpl @@ -206,19 +206,24 @@ $(document).ready(function () { {if isset($pack) && $pack->isPack($product->id)}

{l s='The sum of prices of the products in the pack is %s%s%s' sprintf=[$currency->prefix,{toolsConvertPrice price=$pack->noPackPrice($product->id)|string_format:$priceDisplayPrecisionFormat},$currency->suffix]}

{/if} *} -
- -
- +
+ +
+ +
-
{* As no use in QloApps currently so commented *} {*
{include file="controllers/products/multishop/checkbox.tpl" field="unit_price" type="unit_price"}
diff --git a/admin/themes/default/template/controllers/orders/modals/_add_order_extra_services_tab_content.tpl b/admin/themes/default/template/controllers/orders/modals/_add_order_extra_services_tab_content.tpl index 048757a04..3dc6241f0 100644 --- a/admin/themes/default/template/controllers/orders/modals/_add_order_extra_services_tab_content.tpl +++ b/admin/themes/default/template/controllers/orders/modals/_add_order_extra_services_tab_content.tpl @@ -91,7 +91,11 @@ {$cartCurrency->sign} - {if Product::PRICE_CALCULATION_METHOD_PER_DAY == $product['price_calculation_method']} + {if Product::getPriceCalculationApplicableDays( + $product['price_calculation_method'], + $selectedRoomServiceProduct['date_from'], + $selectedRoomServiceProduct['date_to'] + ) > 1} {l s='/ night'} {/if}
@@ -132,8 +136,13 @@
diff --git a/admin/themes/default/template/controllers/orders/modals/_extra_services_service_products_tab_content.tpl b/admin/themes/default/template/controllers/orders/modals/_extra_services_service_products_tab_content.tpl index 8fb331302..4f6ce1c58 100644 --- a/admin/themes/default/template/controllers/orders/modals/_extra_services_service_products_tab_content.tpl +++ b/admin/themes/default/template/controllers/orders/modals/_extra_services_service_products_tab_content.tpl @@ -82,7 +82,11 @@
{$currencySign} - {if Product::PRICE_CALCULATION_METHOD_PER_DAY == $service.price_calculation_method} + {if Product::getPriceCalculationApplicableDays( + $service.price_calculation_method, + $additionalServices['date_from'], + $additionalServices['date_to'] + ) > 1} {l s='/ night'} {/if}
@@ -152,9 +156,13 @@
{$currencySign} - {if Product::PRICE_CALCULATION_METHOD_PER_DAY == $product['price_calculation_method']} - {l s='/ night'} - {/if} + {if Product::getPriceCalculationApplicableDays( + $product['price_calculation_method'], + $additionalServices['date_from'], + $additionalServices['date_to'] + ) > 1} + {l s='/ night'} + {/if}
@@ -191,8 +199,13 @@
@@ -286,9 +299,13 @@ {displayPrice price=$service['unit_price_tax_excl'] currency=$orderCurrency} - {if $service['price_calculation_method'] == Product::PRICE_CALCULATION_METHOD_PER_DAY} - {l s='/ night'} - {/if} + {if Product::getPriceCalculationApplicableDays( + $service['price_calculation_method'], + $additionalServices['date_from'], + $additionalServices['date_to'] + ) > 1} + {l s='/ night'} + {/if} {displayPrice price=$service['total_price_tax_excl'] currency=$orderCurrency} diff --git a/classes/Product.php b/classes/Product.php index fc962d3c0..cfb27c0ad 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -566,8 +566,15 @@ class ProductCore extends ObjectModel const PRICE_ADDITION_TYPE_WITH_ROOM = 1; const PRICE_ADDITION_TYPE_INDEPENDENT = 2; - const PRICE_CALCULATION_METHOD_PER_BOOKING = 1; - const PRICE_CALCULATION_METHOD_PER_DAY = 2; + const PRICE_CALCULATION_METHOD_PER_DAY = 1; + + const PRICE_CALCULATION_METHOD_ONLY_CHECKIN_DAY = 1; + const PRICE_CALCULATION_METHOD_ONLY_CHECKOUT_DAY = 2; + const PRICE_CALCULATION_METHOD_ONLY_DURINGSTAY_DAY = 3; + const PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY = 4; + const PRICE_CALCULATION_METHOD_CHECKIN_AND_DURINGSTAY = 5; + const PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURINGSTAY = 6; + const PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURINGSTAY = 7; const STANDARD_PRODUCT_ADDRESS_PREFERENCE_CUSTOMER = 1; const STANDARD_PRODUCT_ADDRESS_PREFERENCE_HOTEL = 2; @@ -6865,12 +6872,54 @@ class ProductCore extends ObjectModel ) ); - if (Product::getProductPriceCalculation($idProduct) == Product::PRICE_CALCULATION_METHOD_PER_DAY - && $dateFrom && $dateTo - ) { - $price = $price * HotelHelper::getNumberOfDays($dateFrom, $dateTo); - } + $numdays = Product::getPriceCalculationApplicableDays( + Product::getProductPriceCalculation($idProduct), + $dateFrom, + $dateTo + ); + $price = $price * $numdays; return $price * (int)$quantity; } + + + public static function getPriceCalculationApplicableDays( + $priceCalculationMethod, + $dateFrom, + $dateTo, + $defaultDays = 1 + ) { + if (empty($dateFrom) || empty($dateTo)) { + return (int) $defaultDays; + } + + $numNights = (int) HotelHelper::getNumberOfDays($dateFrom, $dateTo); + if ($numNights <= 0) { + return (int) $defaultDays; + } + + switch ((int) $priceCalculationMethod) { + case self::PRICE_CALCULATION_METHOD_ONLY_CHECKIN_DAY: + case self::PRICE_CALCULATION_METHOD_ONLY_CHECKOUT_DAY: + return 1; + + case self::PRICE_CALCULATION_METHOD_ONLY_DURINGSTAY_DAY: + return max($numNights - 1, 1); + + case self::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY: + return 2; + + case self::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURINGSTAY: + case self::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURINGSTAY: + return $numNights; + + case self::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURINGSTAY: + return $numNights + 1; + + default: + return $numNights; + } + } + } + diff --git a/classes/webservice/WebserviceSpecificManagementBookings.php b/classes/webservice/WebserviceSpecificManagementBookings.php index 10e52dab0..cc67e3351 100644 --- a/classes/webservice/WebserviceSpecificManagementBookings.php +++ b/classes/webservice/WebserviceSpecificManagementBookings.php @@ -2297,10 +2297,13 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We ))) { foreach ($services as $service) { $insertedServiceProductIdOrderDetail = $objBookingDetail->getLastInsertedServiceIdOrderDetail($objOrder->id, $service['id_product']); - $numDays = 1; - if (Product::getProductPriceCalculation($service['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $numDays = HotelHelper::getNumberOfDays($objBookingDetail->date_from, $objBookingDetail->date_to); - } + + $numDays = Product::getPriceCalculationApplicableDays( + Product::getProductPriceCalculation($service['id_product']), + $objBookingDetail->date_from, + $objBookingDetail->date_to + ); + $totalPriceTaxExcl = Product::getServiceProductPrice( $service['id_product'], 0, @@ -2653,9 +2656,12 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We foreach ($selectedAdditonalServices[$idHotelBooking]['additional_services'] as $service) { $serviceOrderDetail = new OrderDetail($service['id_order_detail']); $cart_quantity = $service['quantity']; - if ($service['price_calculation_method'] == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $cart_quantity = $cart_quantity * $quantity; - } + $serviceApplicableDays = Product::getPriceCalculationApplicableDays( + $service['price_calculation_method'], + $dateFrom, + $dateTo + ); + $cart_quantity = $cart_quantity * $serviceApplicableDays; if ($cart_quantity >= $serviceOrderDetail->product_quantity) { $serviceOrderDetail->delete(); @@ -3169,10 +3175,11 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We $priceTaxExcl = $objServiceProductOrderDetail->total_price_tax_excl; $priceTaxIncl = $objServiceProductOrderDetail->total_price_tax_incl; $objHotelBookingDetail = new HotelBookingDetail($objServiceProductOrderDetail->id_htl_booking_detail); - $numDays = 1; - if (Product::getProductPriceCalculation($service['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to); - } + $numDays = Product::getPriceCalculationApplicableDays( + Product::getProductPriceCalculation($service['id_product']), + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to + ); $quantity = $objOrderDetail->product_quantity * $numDays; if ($objServiceProductOrderDetail->delete()) { @@ -3264,10 +3271,11 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We $insertedServiceProductIdOrderDetail = $objHotelBookingDetail->getLastInsertedServiceIdOrderDetail($objOrder->id, $service['id_product']); $objOrderDetail = new OrderDetail($insertedServiceProductIdOrderDetail); - $numDays = 1; - if (Product::getProductPriceCalculation($product['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to); - } + $numDays = Product::getPriceCalculationApplicableDays( + Product::getProductPriceCalculation($product['id_product']), + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to + ); $quantity = $objServiceProductCartDetail->quantity * $numDays; @@ -3687,17 +3695,18 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We $services['id_service'] = (int) $service['id_product']; $services['name'] = $service['name']; $services['quantity'] = (int) $service['quantity']; - $services['unit_price_without_tax'] = Tools::ps_round(($service['total_price_tax_excl'] / $services['quantity']), _PS_PRICE_COMPUTE_PRECISION_); + $applicableDays = Product::getPriceCalculationApplicableDays( + $service['price_calculation_method'], + $additionalService['date_from'], + $additionalService['date_to'] + ); + $unitDivisor = max(1, ((int) $services['quantity'] * (int) $applicableDays)); + $services['unit_price_without_tax'] = Tools::ps_round(($service['total_price_tax_excl'] / $unitDivisor), _PS_PRICE_COMPUTE_PRECISION_); $services['total_price_without_tax'] = Tools::ps_round(($service['total_price_tax_excl']), _PS_PRICE_COMPUTE_PRECISION_); $services['total_tax'] = Tools::ps_round(($service['total_price_tax_incl'] - $service['total_price_tax_excl']), _PS_PRICE_COMPUTE_PRECISION_); - $objProduct = new Product($service['id_product']); - $services['per_night'] = 0; - if ($objProduct->price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $services['per_night'] = 1; - } - - $services['price_mode'] = (int) $objProduct->price_calculation_method; + $services['per_night'] = ((int) $applicableDays > 1) ? 1 : 0; + $services['price_mode'] = (int) $service['price_calculation_method']; $roomInfo['services'][] = $services; } } diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index f76331422..626185f1f 100644 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -1205,10 +1205,12 @@ class AdminCartsControllerCore extends AdminController if ($serviceProducts) { foreach ($serviceProducts as $key => $servProduct) { - $numDays = 1; - if (Product::PRICE_CALCULATION_METHOD_PER_DAY == $servProduct['price_calculation_method']) { - $numDays = HotelHelper::getNumberOfDays($dateFrom, $dateTo); - } + $numDays = Product::getPriceCalculationApplicableDays( + $servProduct['price_calculation_method'], + $dateFrom, + $dateTo + ); + $serviceProducts[$key]['price_tax_exc'] = Product::getServiceProductPrice( $servProduct['id_product'], 0, diff --git a/controllers/admin/AdminNormalProductsController.php b/controllers/admin/AdminNormalProductsController.php index 43838ccc8..6827d5811 100644 --- a/controllers/admin/AdminNormalProductsController.php +++ b/controllers/admin/AdminNormalProductsController.php @@ -200,8 +200,13 @@ class AdminNormalProductsControllerCore extends AdminController Product::PRICE_ADDITION_TYPE_INDEPENDENT => $this->l('Convenience Fee') ); $priceCalculationMethod = array( - Product::PRICE_CALCULATION_METHOD_PER_BOOKING => $this->l('Add price once for the booking range'), - Product::PRICE_CALCULATION_METHOD_PER_DAY => $this->l('Add price for each day of booking') + Product::PRICE_CALCULATION_METHOD_ONLY_CHECKIN_DAY => $this->l('Only check-in day'), + Product::PRICE_CALCULATION_METHOD_ONLY_CHECKOUT_DAY => $this->l('Only check-out day'), + Product::PRICE_CALCULATION_METHOD_ONLY_DURINGSTAY_DAY => $this->l('Only during-stay days'), + Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY => $this->l('Check-in and check-out days'), + Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURINGSTAY => $this->l('Check-in | during-stay days'), + Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURINGSTAY => $this->l('Check-out | during-stay days'), + Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURINGSTAY => $this->l('Check-in | check-out | during-stay days'), ); $this->_join .= ' @@ -222,7 +227,7 @@ class AdminNormalProductsControllerCore extends AdminController LEFT JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (rsp.`id_element` = hrt.`id_product` AND rsp.`element_type` = '.(int)RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE.') '.HotelBranchInformation::addHotelRestriction(false, 'hrt'); - $this->_select .= ' IF(a.`auto_add_to_cart`, "'.$this->l('Yes').'", "'.$this->l('No').'") as auto_added, IF(a.`auto_add_to_cart`, 1, 0) as badge_success, IF(a.`show_at_front`, "'.$this->l('Yes').'", "'.$this->l('No').'") as show_at_front_txt, IF(a.`price_calculation_method` = '.(int)Product::PRICE_CALCULATION_METHOD_PER_DAY.', "'.$this->l('Per Day').'", "'.$this->l('Per Booking').'") as price_calculation_method_txt, (SELECT COUNT(hri.`id`) FROM `'._DB_PREFIX_.'htl_room_information` hri WHERE hri.`id_product` = a.`id_product`) as num_rooms, '; + $this->_select .= ' IF(a.`auto_add_to_cart`, "'.$this->l('Yes').'", "'.$this->l('No').'") as auto_added, IF(a.`auto_add_to_cart`, 1, 0) as badge_success, IF(a.`show_at_front`, "'.$this->l('Yes').'", "'.$this->l('No').'") as show_at_front_txt, CASE a.`price_calculation_method` WHEN '.Product::PRICE_CALCULATION_METHOD_ONLY_CHECKIN_DAY.' THEN "'.$this->l('Only check-in day').'" WHEN '.Product::PRICE_CALCULATION_METHOD_ONLY_CHECKOUT_DAY.' THEN "'.$this->l('Only check-out day').'" WHEN '.Product::PRICE_CALCULATION_METHOD_ONLY_DURINGSTAY_DAY.' THEN "'.$this->l('Only during-stay days').'" WHEN '.Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY.' THEN "'.$this->l('Check-in and check-out days').'" WHEN '.Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURINGSTAY.' THEN "'.$this->l('Check-in | during-stay days').'" WHEN '.Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURINGSTAY.' THEN "'.$this->l('Check-out | during-stay days').'" WHEN '.Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURINGSTAY.' THEN "'.$this->l('Check-in | check-out | during-stay days').'" ELSE "'.$this->l('Only check-in day').'" END as price_calculation_method_txt, (SELECT COUNT(hri.`id`) FROM `'._DB_PREFIX_.'htl_room_information` hri WHERE hri.`id_product` = a.`id_product`) as num_rooms, '; $this->_select .= ' COUNT(hrt.`id_product`) as products_associated, '; $this->_select .= 'shop.`name` AS `shopname`, a.`id_shop_default`, '; $this->_select .= $alias_image.'.`id_image` AS `id_image`, cl.`name` AS `name_category`, '.$alias.'.`price`, 0 AS `price_final`, a.`is_virtual`, pd.`nb_downloadable`, sav.`quantity` AS `sav_quantity`, '.$alias.'.`active`, IF(sav.`quantity`<=0, 1, 0) AS `badge_danger`'; diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 30026bcca..e9f5be74f 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -5342,10 +5342,11 @@ class AdminOrdersControllerCore extends AdminController )) { foreach ($services as $service) { $insertedServiceProductIdOrderDetail = $objBookingDetail->getLastInsertedServiceIdOrderDetail($order->id, $service['id_product']); - $numDays = 1; - if (Product::getProductPriceCalculation($service['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $numDays = HotelHelper::getNumberOfDays($objBookingDetail->date_from, $objBookingDetail->date_to); - } + $numDays = Product::getPriceCalculationApplicableDays( + Product::getProductPriceCalculation($service['id_product']), + $objBookingDetail->date_from, + $objBookingDetail->date_to + ); $totalPriceTaxExcl = Product::getServiceProductPrice( (int) $service['id_product'], @@ -6519,9 +6520,12 @@ class AdminOrdersControllerCore extends AdminController $serviceOrderDetail = new OrderDetail($service['id_order_detail']); $cart_quantity = $service['quantity']; - if ($service['price_calculation_method'] == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $cart_quantity = $cart_quantity * $product_quantity; - } + $serviceApplicableDays = Product::getPriceCalculationApplicableDays( + $service['price_calculation_method'], + $selectedAdditonalServices[$idHotelBooking]['date_from'], + $selectedAdditonalServices[$idHotelBooking]['date_to'] + ); + $cart_quantity = $cart_quantity * $serviceApplicableDays; if ($cart_quantity >= $serviceOrderDetail->product_quantity) { $serviceOrderDetail->delete(); } else { @@ -7702,10 +7706,11 @@ class AdminOrdersControllerCore extends AdminController $this->context->cart = $cart; $this->context->customer = new Customer($order->id_customer); - $numDays = 1; - if (Product::getProductPriceCalculation($service['id']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to); - } + $numDays = Product::getPriceCalculationApplicableDays( + Product::getProductPriceCalculation($service['id']), + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to + ); $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); $initialServicePrice = Product::getServiceProductPrice( @@ -8013,10 +8018,11 @@ class AdminOrdersControllerCore extends AdminController $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); $cartProductProcessed = 1; - $numDays = 1; - if (Product::getProductPriceCalculation($objServiceProduct->id) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to); - } + $numDays = Product::getPriceCalculationApplicableDays( + Product::getProductPriceCalculation($objServiceProduct->id), + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to + ); foreach ($productList as &$product) { // This is used to get the actual quanity of the service as it is calculated incorrectly if the service is per night if ($idRoomTypeServProductCart = $objServiceProductCartDetail->alreadyExists( diff --git a/modules/hotelreservationsystem/classes/HotelHelper.php b/modules/hotelreservationsystem/classes/HotelHelper.php index a196694f5..709a9b23a 100644 --- a/modules/hotelreservationsystem/classes/HotelHelper.php +++ b/modules/hotelreservationsystem/classes/HotelHelper.php @@ -2155,7 +2155,7 @@ class HotelHelper 'price' => '250', 'auto_add_to_cart' => 1, 'show_at_front' => 0, - 'price_calculation_method' => Product::PRICE_CALCULATION_METHOD_PER_DAY, + 'price_calculation_method' => Product::PRICE_CALCULATION_METHOD_ONLY_DURINGSTAY_DAY, 'price_addition_type' => Product::PRICE_ADDITION_TYPE_WITH_ROOM, 'en' => array( 'name' => 'Room Maintenance Fees', @@ -2220,7 +2220,7 @@ class HotelHelper 'price' => '50', 'auto_add_to_cart' => 0, 'show_at_front' => 1, - 'price_calculation_method' => Product::PRICE_CALCULATION_METHOD_PER_BOOKING, + 'price_calculation_method' => Product::PRICE_CALCULATION_METHOD_ONLY_DURINGSTAY_DAY, 'price_addition_type' => Product::PRICE_ADDITION_TYPE_WITH_ROOM, 'en' => array( 'name' => 'Airport Shuttle', @@ -2252,7 +2252,7 @@ class HotelHelper 'price' => '200', 'auto_add_to_cart' => 0, 'show_at_front' => 1, - 'price_calculation_method' => Product::PRICE_CALCULATION_METHOD_PER_BOOKING, + 'price_calculation_method' => Product::PRICE_CALCULATION_METHOD_ONLY_DURINGSTAY_DAY, 'price_addition_type' => Product::PRICE_ADDITION_TYPE_WITH_ROOM, 'en' => array( 'name' => 'Cab on Demand', @@ -2284,7 +2284,7 @@ class HotelHelper 'price' => '350', 'auto_add_to_cart' => 0, 'show_at_front' => 1, - 'price_calculation_method' => Product::PRICE_CALCULATION_METHOD_PER_DAY, + 'price_calculation_method' => Product::PRICE_CALCULATION_METHOD_ONLY_DURINGSTAY_DAY, 'price_addition_type' => Product::PRICE_ADDITION_TYPE_WITH_ROOM, 'en' => array( 'name' => 'Breakfast', @@ -2316,7 +2316,7 @@ class HotelHelper 'price' => '450', 'auto_add_to_cart' => 0, 'show_at_front' => 1, - 'price_calculation_method' => Product::PRICE_CALCULATION_METHOD_PER_DAY, + 'price_calculation_method' => Product::PRICE_CALCULATION_METHOD_ONLY_DURINGSTAY_DAY, 'price_addition_type' => Product::PRICE_ADDITION_TYPE_WITH_ROOM, 'en' => array( 'name' => 'Dinner', diff --git a/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php index 25a1edfcb..1c93321d9 100644 --- a/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php @@ -89,11 +89,13 @@ class ServiceProductCartDetail extends ObjectModel $objServiceProductCartDetail = new ServiceProductCartDetail($product['id_service_product_cart_detail']) )) { $updateQty = $product['quantity']; - if (Product::getProductPriceCalculation($product['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $objHotelCartBookingData = new HotelCartBookingData($htlCartBookingId); - $numdays = HotelHelper::getNumberOfDays($objHotelCartBookingData->date_from, $objHotelCartBookingData->date_to); - $updateQty *= $numdays; - } + $objHotelCartBookingData = new HotelCartBookingData($htlCartBookingId); + $numdays = Product::getPriceCalculationApplicableDays( + Product::getProductPriceCalculation($product['id_product']), + $objHotelCartBookingData->date_from, + $objHotelCartBookingData->date_to + ); + $updateQty *= $numdays; if ($objServiceProductCartDetail->delete()) { $objCart = new Cart($product['id_cart']); if (isset(Context::getContext()->controller->controller_type)) { @@ -247,13 +249,11 @@ class ServiceProductCartDetail extends ObjectModel $product['htl_cart_booking_id'] ); } else { - $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; - } + $numDays = Product::getPriceCalculationApplicableDays( + $objProduct->price_calculation_method, + $product['date_from'], + $product['date_to'] + ); $priceTaxIncl = Product::getServiceProductPrice( $objProduct->id, @@ -455,14 +455,13 @@ class ServiceProductCartDetail extends ObjectModel } if ($objServiceProductCartDetail->save()) { - if ($objProduct->price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - if (Validate::isLoadedObject($objHotelCartBooking = new HotelCartBookingData($idHtlCartData))) { - $numDays = HotelHelper::getNumberOfDays( - $objHotelCartBooking->date_from, - $objHotelCartBooking->date_to - ); - $quantity = $objServiceProductCartDetail->quantity * $numDays; - } + if (Validate::isLoadedObject($objHotelCartBooking = new HotelCartBookingData($idHtlCartData))) { + $numDays = Product::getPriceCalculationApplicableDays( + $objProduct->price_calculation_method, + $objHotelCartBooking->date_from, + $objHotelCartBooking->date_to + ); + $quantity = $objServiceProductCartDetail->quantity * $numDays; } $objCart = new Cart($idCart); diff --git a/themes/hotel-reservation-theme/_partials/cart_booking_demands.tpl b/themes/hotel-reservation-theme/_partials/cart_booking_demands.tpl index f74c3b628..5a3db8aaa 100644 --- a/themes/hotel-reservation-theme/_partials/cart_booking_demands.tpl +++ b/themes/hotel-reservation-theme/_partials/cart_booking_demands.tpl @@ -148,12 +148,19 @@
-
- {if ($product.show_price && !isset($restricted_country_mode)) || isset($groups)} - {if !$priceDisplay}{convertPrice price=$product.price_tax_incl}{else}{convertPrice price=$product.price_tax_exc}{/if}{if $product.price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY}{l s='/Night'}{/if} +
+ {if ($product.show_price && !isset($restricted_country_mode)) || isset($groups)} + + {if !$priceDisplay}{convertPrice price=$product.price_tax_incl}{else}{convertPrice price=$product.price_tax_exc}{/if} + {if Product::getPriceCalculationApplicableDays( + $product.price_calculation_method, + $cartRoom.date_from|default:'', + $cartRoom.date_to|default:'' + ) > 1}{l s='/Night'}{/if} + - {/if} -
+ {/if} +
{/foreach} {/if} diff --git a/themes/hotel-reservation-theme/_partials/service-products-list-row.tpl b/themes/hotel-reservation-theme/_partials/service-products-list-row.tpl index 19ac25070..5a8896426 100644 --- a/themes/hotel-reservation-theme/_partials/service-products-list-row.tpl +++ b/themes/hotel-reservation-theme/_partials/service-products-list-row.tpl @@ -53,7 +53,14 @@ {if !$PS_CATALOG_MODE && !$order_date_restrict && ($service_product.show_price && !isset($restricted_country_mode))}
{block name='service_product_price'} - {if !$priceDisplay}{convertPrice price=$service_product.price_tax_incl}{else}{convertPrice price=$service_product.price_tax_exc}{/if}{if $service_product.price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY}{l s='/Night'}{/if} + {if !$priceDisplay}{convertPrice price=$service_product.price_tax_incl}{else}{convertPrice price=$service_product.price_tax_exc}{/if} + {if Product::getPriceCalculationApplicableDays( + $service_product.price_calculation_method, + $service_product.date_from|default:$date_from|default:'', + $service_product.date_to|default:$date_to|default:'' + ) > 1} + {l s='/Night'} + {/if} {/block} {if $service_product.allow_multiple_quantity && $service_product.available_for_order && $service_product.max_quantity > 0}