From 4436fd016c3f3da874d0a303cb73be8fdefb38ba Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 14 Feb 2025 13:19:20 +0530 Subject: [PATCH 1/5] Optmized the functions and removed non rquired object initialization to reduce stress --- classes/Cart.php | 1 - classes/Product.php | 37 ++++++++++++++----- .../classes/HotelBranchInformation.php | 14 +++++-- .../classes/HotelCartBookingData.php | 2 +- .../classes/HotelRoomType.php | 20 +++++++--- .../classes/HotelRoomTypeFeaturePricing.php | 6 +-- .../classes/RoomTypeServiceProduct.php | 1 - .../RoomTypeServiceProductCartDetail.php | 5 +-- 8 files changed, 57 insertions(+), 29 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index 5255c580c..9fc023781 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -2296,7 +2296,6 @@ class CartCore extends ObjectModel $orderPackage = array(); $serviceProducts = array(); $objRoomType = new HotelRoomType(); - $objHtlCartBookingData = new HotelCartBookingData(); $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail(); $objHotelServiceProductCartDetail = new HotelServiceProductCartDetail(); foreach ($final_package_list as $id_address => $packages) { diff --git a/classes/Product.php b/classes/Product.php index f62901fe9..e5a74106d 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -931,12 +931,21 @@ class ProductCore extends ObjectModel ), 'id_product = '.(int)$id_product); } - public static function getProductPriceCalculation($id_product) { - return Db::getInstance()->getValue( - 'SELECT product_shop.`price_calculation_method` - FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' - WHERE p.`id_product` = '.(int)$id_product - ); + public static function getProductPriceCalculation($id_product) + { + $cache_key = 'Product::getProductPriceCalculation'.(int)$id_product; + if (!Cache::isStored($cache_key)) { + $res = Db::getInstance()->getValue( + 'SELECT product_shop.`price_calculation_method` + FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' + WHERE p.`id_product` = '.(int)$id_product + ); + Cache::store($cache_key, $res); + } else { + $res = Cache::retrieve($cache_key); + } + + return $res; } /** @@ -975,10 +984,18 @@ class ProductCore extends ObjectModel public static function isBookingProduct($id_product) { - return Db::getInstance()->getValue(' - SELECT `booking_product` FROM `'._DB_PREFIX_.'product` p - WHERE p.`id_product` = '.(int)$id_product - ); + $cache_key = 'Product::isBookingProduct'.(int)$id_product; + if (!Cache::isStored($cache_key)) { + $res = Db::getInstance()->getValue(' + SELECT `booking_product` FROM `'._DB_PREFIX_.'product` p + WHERE p.`id_product` = '.(int)$id_product + ); + Cache::store($cache_key, $res); + } else { + $res = Cache::retrieve($cache_key); + } + + return $res; } public function delete() diff --git a/modules/hotelreservationsystem/classes/HotelBranchInformation.php b/modules/hotelreservationsystem/classes/HotelBranchInformation.php index c2779a01e..b7c85eac4 100644 --- a/modules/hotelreservationsystem/classes/HotelBranchInformation.php +++ b/modules/hotelreservationsystem/classes/HotelBranchInformation.php @@ -527,9 +527,17 @@ class HotelBranchInformation extends ObjectModel */ public static function getHotelIdByIdCategory($id_category) { - return Db::getInstance()->getValue( - 'SELECT `id` FROM `'._DB_PREFIX_.'htl_branch_info` WHERE id_category = '.(int)$id_category - ); + $cache_key = 'HotelBranchInformation::getHotelIdByIdCategory'.(int)$id_category; + if (!Cache::isStored($cache_key)) { + $res = Db::getInstance()->getValue( + 'SELECT `id` FROM `'._DB_PREFIX_.'htl_branch_info` WHERE id_category = '.(int)$id_category + ); + Cache::store($cache_key, $res); + } else { + $res = Cache::retrieve($cache_key); + } + + return $res; } /** diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 0cd9c678d..c2d9bf333 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -1350,7 +1350,7 @@ class HotelCartBookingData extends ObjectModel * @param [int] $id_group [id_group for which price is need (if available for the passed group)] * @return [array|false] [returns array containg info of the feature plan if foung otherwise returns false] */ - public function getProductFeaturePricePlanByDateByPriority( + public static function getProductFeaturePricePlanByDateByPriority( $id_product, $date, $id_group, diff --git a/modules/hotelreservationsystem/classes/HotelRoomType.php b/modules/hotelreservationsystem/classes/HotelRoomType.php index a523d4bc4..03112f59b 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomType.php +++ b/modules/hotelreservationsystem/classes/HotelRoomType.php @@ -248,12 +248,20 @@ class HotelRoomType extends ObjectModel */ public static function getHotelIdAddressByIdProduct($id_product) { - return Db::getInstance()->getValue( - 'SELECT `id_address` from `'._DB_PREFIX_.'address` a - INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt - ON (hrt.`id_hotel` = a.`id_hotel`) - WHERE hrt.`id_product` = '.(int)$id_product.' AND a.`deleted` = 0 - '); + $cache_key = 'HotelRoomType::getHotelIdAddressByIdProduct'.(int)$id_product; + if (!Cache::isStored($cache_key)) { + $res = Db::getInstance()->getValue( + 'SELECT `id_address` from `'._DB_PREFIX_.'address` a + INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt + ON (hrt.`id_hotel` = a.`id_hotel`) + WHERE hrt.`id_product` = '.(int)$id_product.' AND a.`deleted` = 0 + '); + Cache::store($cache_key, $res); + } else { + $res = Cache::retrieve($cache_key); + } + + return $res; } /** diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index fd1ef9d93..82621b434 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -671,9 +671,8 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $context = Context::getContext(); $id_currency = Validate::isLoadedObject($context->currency) ? (int)$context->currency->id : (int)Configuration::get('PS_CURRENCY_DEFAULT'); - $hotelCartBookingData = new HotelCartBookingData(); for($currentDate = date('Y-m-d', strtotime($date_from)); $currentDate < date('Y-m-d', strtotime($date_to)); $currentDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate)))) { - if ($use_reduc && ($featurePrice = $hotelCartBookingData->getProductFeaturePricePlanByDateByPriority( + if ($use_reduc && ($featurePrice = HotelCartBookingData::getProductFeaturePricePlanByDateByPriority( $id_product, $currentDate, $id_group, @@ -826,8 +825,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $totalDurationPriceTI = $totalDurationPrice['total_price_tax_incl']; $totalDurationPriceTE = $totalDurationPrice['total_price_tax_excl']; - $objHotelBookingDetail = new HotelBookingDetail(); - $numDaysInDuration = $objHotelBookingDetail->getNumberOfDays($dateFrom, $dateTo); + $numDaysInDuration = HotelHelper::getNumberOfDays($dateFrom, $dateTo); if ($use_tax) { $pricePerDay = $totalDurationPriceTI/$numDaysInDuration; } else { diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php index 7c80b17e1..033222b22 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php @@ -184,7 +184,6 @@ class RoomTypeServiceProduct extends ObjectModel true, $subCategory )) { - $objHotelRoomType = new HotelRoomType(); $serviceProducts = Product::getProductsProperties($idLang, $serviceProducts); $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); foreach($serviceProducts as &$serviceProduct) { diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php index fec2fed2c..c7f894b18 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php @@ -267,10 +267,9 @@ class RoomTypeServiceProductCartDetail extends ObjectModel if ($getTotalPrice) { $totalPrice = 0; } - $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); - $objHotelRoomType = new HotelRoomType(); - $selectedServiceProducts = array(); + $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); + $selectedServiceProducts = array(); if ($serviceProducts = Db::getInstance()->executeS($sql)) { foreach ($serviceProducts as $product) { $qty = $product['quantity'] ? (int)$product['quantity'] : 1; From 8751d3385af380049dbf89ea8a25dc19fef57f63 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Mon, 3 Mar 2025 15:29:20 +0530 Subject: [PATCH 2/5] Updated the data for front search function to get the data for the multiple room types at once --- .../classes/HotelBookingDetail.php | 28 +++- .../classes/HotelCartBookingData.php | 57 +++++++ .../classes/HotelOrderRestrictDate.php | 14 +- .../classes/HotelRoomTypeFeaturePricing.php | 145 ++++++++++++++++++ .../classes/RoomTypeServiceProduct.php | 35 +++++ .../classes/RoomTypeServiceProductPrice.php | 37 +++-- .../wkhotelfilterblock/wkhotelfilterblock.php | 20 ++- 7 files changed, 311 insertions(+), 25 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index 97f037fcd..3d4df2c96 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -1679,8 +1679,17 @@ class HotelBookingDetail extends ObjectModel if (!$only_search_data) { if (!empty($bookingData)) { - $objRoomType = new HotelRoomType(); - + $idProducts = array_keys($bookingData['rm_data']); + $productsFeaturePrice = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices( + $idProducts, + $date_from, + $date_to + ); + if (!($numDays = HotelHelper::getNumberOfDays($date_from, $date_to))) { + $numDays = 1; + } + $useTax = self::useTax(); + $productsFeaturePriceWithoutReduction = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices($idProducts, $date_from, $date_to, 0, 1, 0); foreach ($bookingData['rm_data'] as $key => $value) { $product_feature = Product::getFrontFeaturesStatic($this->context->language->id, $value['id_product']); $prod_amen = array(); @@ -1699,14 +1708,23 @@ class HotelBookingDetail extends ObjectModel continue; } } - $productFeaturePrice = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax()); + if ($useTax) { + $prod_price = $productsFeaturePrice[$value['id_product']]['product_price_tax_incl']; + $productFeaturePrice = $productsFeaturePrice[$value['id_product']]['total_price_tax_incl'] / $numDays; + } else { + $prod_price = $productsFeaturePrice[$value['id_product']]['product_price_tax_excl']; + $productFeaturePrice = $productsFeaturePrice[$value['id_product']]['total_price_tax_excl'] / $numDays; + } if (!empty($price) && ($price['from'] > $productFeaturePrice || $price['to'] < $productFeaturePrice)) { unset($bookingData['rm_data'][$key]); continue; } if (count($value['data']['available'])) { - $prod_price = Product::getPriceStatic($value['id_product'], self::useTax()); - $productPriceWithoutReduction = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax(), 0, 0, 0, 0, 1, 0); + if ($useTax) { + $productPriceWithoutReduction = $productsFeaturePriceWithoutReduction[$value['id_product']]['total_price_tax_incl'] / $numDays; + } else { + $productPriceWithoutReduction = $productsFeaturePriceWithoutReduction[$value['id_product']]['total_price_tax_excl'] / $numDays; + } $cover_image_arr = Product::getCover($value['id_product']); if (!empty($cover_image_arr)) { $cover_img = $this->context->link->getImageLink($value['link_rewrite'], $value['id_product'].'-'.$cover_image_arr['id_image'], 'home_default'); diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 7f8a3e151..4635f155f 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -1415,6 +1415,63 @@ class HotelCartBookingData extends ObjectModel return false; } + public static function getProductsWiseFeaturePricePlansByDateRangeByPriority( + $idProducts, + $dateFrom, + $dateTo, + $idGroup + ) { + $featurePricePriority = Configuration::get('HTL_FEATURE_PRICING_PRIORITY'); + if ($featurePricePriority = explode(';', $featurePricePriority)) { + if ($featurePrices = Db::getInstance()->executeS( + 'SELECT fp.`id_feature_price`, fp.`id_product`, fp.`date_from`, fp.`date_to`, fp.`impact_way`, fp.`is_special_days_exists`, + fp.`date_selection_type`, fp.`special_days`, fp.`impact_type`, fp.`impact_value` + FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing` fp'. + (Group::isFeatureActive() ? ' INNER JOIN `'._DB_PREFIX_.'htl_room_type_feature_pricing_group` fpg + ON (fp.`id_feature_price` = fpg.`id_feature_price` AND fpg.`id_group` = '.(int) $idGroup.')' : '').' + WHERE fp.`id_cart` = 0 AND fp.`id_product` IN('.implode(', ', $idProducts).') AND fp.`active`=1 + AND fp.`date_from` <= \''.pSQL($dateTo).'\' AND fp.`date_to` >= \''.pSQL($dateFrom).'\' ' + )) { + $idProductsWisefeaturePrice = array(); + foreach ($featurePrices as $featurePriceKey => $featurePrice) { + for ($currentDate = strtotime($featurePrice['date_from']); $currentDate <= strtotime($featurePrice['date_to']); $currentDate += _TIME_1_DAY_) { + if (!isset($featurePrice['priority'])) { + if ($featurePrice['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { + $featurePrices[$featurePriceKey]['priority'] = $featurePrice['priority'] = array_search('specific_date', $featurePricePriority); + } else if ($featurePrice['is_special_days_exists']) { + $featurePrices[$featurePriceKey]['priority'] = $featurePrice['priority'] = array_search('special_day', $featurePricePriority); + } else if ($featurePrice['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { + $featurePrices[$featurePriceKey]['priority'] = $featurePrice['priority'] = array_search('date_range', $featurePricePriority); + } + } + + if ((int) $featurePrice['is_special_days_exists']) { + $specialDays = json_decode($featurePrice['special_days']); + if (!in_array(strtolower(date('D', $currentDate)), $specialDays)) { + continue; + } + } else if ($featurePrice['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC && $currentDate != strtotime($featurePrice['date_from'])) { + continue; + } + + if (isset($idProductsWisefeaturePrice[$featurePrice['id_product']][$currentDate]) + && $idProductsWisefeaturePrice[$featurePrice['id_product']][$currentDate]['priority'] > $featurePrice['priority'] + ) { + // replacing the feature prices if a feature price of more priority is available. + $idProductsWisefeaturePrice[$featurePrice['id_product']][$currentDate] = $featurePrice; + } else { + $idProductsWisefeaturePrice[$featurePrice['id_product']][$currentDate] = $featurePrice; + } + } + } + + return $idProductsWisefeaturePrice; + } + } + + return false; + } + /** * Returns booking info of the current cart * @param integer $detailed : send 1 for detailedd info and 0 for normal info diff --git a/modules/hotelreservationsystem/classes/HotelOrderRestrictDate.php b/modules/hotelreservationsystem/classes/HotelOrderRestrictDate.php index d623d8bf6..0fdaaf6e9 100644 --- a/modules/hotelreservationsystem/classes/HotelOrderRestrictDate.php +++ b/modules/hotelreservationsystem/classes/HotelOrderRestrictDate.php @@ -45,9 +45,17 @@ class HotelOrderRestrictDate extends ObjectModel public static function getDataByHotelId($idHotel) { - return Db::getInstance()->getRow( - 'SELECT * FROM `'._DB_PREFIX_.'htl_order_restrict_date` ord WHERE ord.`id_hotel` = '.(int) $idHotel - ); + $cache_key = 'HotelOrderRestrictDate::getDataByHotelId'.(int)$idHotel; + if (!Cache::isStored($cache_key)) { + $res = Db::getInstance()->getRow( + 'SELECT * FROM `'._DB_PREFIX_.'htl_order_restrict_date` ord WHERE ord.`id_hotel` = '.(int) $idHotel + ); + Cache::store($cache_key, $res); + } else { + $res = Cache::retrieve($cache_key); + } + + return $res; } /*Max date of ordering for order restrict*/ diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index fd1ef9d93..2acd9ed25 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -790,6 +790,151 @@ class HotelRoomTypeFeaturePricing extends ObjectModel return $totalPrice; } + public static function getRoomTypesTotalPrices( + $idProducts = array(), + $dateFrom, + $dateTo, + $idGroup = 0, + $withAutoRoomservices = 1, + $useReduc = 1 + ) { + if (!$idProducts) { + return false; + } + + // Initializations + if (!$idGroup) { + $idGroup = (int)Group::getCurrent()->id; + } + + // if dateFrom and dateTo are same then dateTo will be the next date date of dateFrom + if (strtotime($dateFrom) == strtotime($dateTo)) { + $dateTo = date('Y-m-d H:i:s', strtotime('+1 day', strtotime($dateFrom))); + } + + + if ($withAutoRoomservices) { + $servicesWithTax = RoomTypeServiceProduct::getAutoAddServicesByIdProducts( + $idProducts, + $dateFrom, + $dateTo, + Product::PRICE_ADDITION_TYPE_WITH_ROOM, + true, + $useReduc + ); + $servicesWithoutTax = RoomTypeServiceProduct::getAutoAddServicesByIdProducts( + $idProducts, + $dateFrom, + $dateTo, + Product::PRICE_ADDITION_TYPE_WITH_ROOM, + false, + $useReduc + ); + } + + $context = Context::getContext(); + $idCurrency = Validate::isLoadedObject($context->currency) ? (int)$context->currency->id : (int)Configuration::get('PS_CURRENCY_DEFAULT'); + $roomTypeWisePricing = array(); + foreach ($idProducts as $idProduct) { + $productPriceTI = Product::getPriceStatic((int) $idProduct, true, false, 6, null, false, $useReduc); + $productPriceTE = Product::getPriceStatic((int) $idProduct, false, false, 6, null, false, $useReduc); + if ($productPriceTE) { + $roomTypeWisePricing[$idProduct]['tax_rate'] = (($productPriceTI-$productPriceTE)/$productPriceTE)*100; + } else { + $roomTypeWisePricing[$idProduct]['tax_rate'] = 0; + } + + $roomTypeWisePricing[$idProduct]['product_price_tax_incl'] = $productPriceTI; + $roomTypeWisePricing[$idProduct]['product_price_tax_excl'] = $productPriceTE; + $roomTypeWisePricing[$idProduct]['total_price_tax_incl'] = 0; + $roomTypeWisePricing[$idProduct]['total_price_tax_excl'] = 0; + } + + $featurePrices = HotelCartBookingData::getProductsWiseFeaturePricePlansByDateRangeByPriority( + $idProducts, + $dateFrom, + $dateTo, + $idGroup + ); + + foreach ($idProducts as $idProduct) { + for($currentDate = strtotime($dateFrom); $currentDate < strtotime($dateTo); $currentDate += _TIME_1_DAY_) { + $featureImpactPriceTI = 0; + $featureImpactPriceTE = 0; + if ($useReduc && isset($featurePrices[$idProduct][$currentDate])) { + $productPriceTI = $roomTypeWisePricing[$idProduct]['product_price_tax_incl']; + $productPriceTE = $roomTypeWisePricing[$idProduct]['product_price_tax_excl']; + $featurePrice = $featurePrices[$idProduct][$currentDate]; + if ($featurePrice['impact_type'] == self::IMPACT_TYPE_PERCENTAGE) { + //percentage + $featureImpactPriceTI = $productPriceTI * ($featurePrice['impact_value'] / 100); + $featureImpactPriceTE = $productPriceTE * ($featurePrice['impact_value'] / 100); + } else { + //Fixed Price + $taxPrice = ($featurePrice['impact_value'] * $roomTypeWisePricing[$idProduct]['tax_rate'])/100; + $featureImpactPriceTE = Tools::convertPrice($featurePrice['impact_value'], $idCurrency); + $featureImpactPriceTI = Tools::convertPrice($featurePrice['impact_value']+$taxPrice, $idCurrency); + } + + if ($featurePrice['impact_way'] == self::IMPACT_WAY_DECREASE) { + // Decrease + $priceWithFeatureTE = ($productPriceTE - $featureImpactPriceTE); + $priceWithFeatureTI = ($productPriceTI - $featureImpactPriceTI); + } elseif ($featurePrice['impact_way'] == self::IMPACT_WAY_INCREASE) { + // Increase + $priceWithFeatureTE = ($productPriceTE + $featureImpactPriceTE); + $priceWithFeatureTI = ($productPriceTI + $featureImpactPriceTI); + } else { + // Fix + $priceWithFeatureTE = $featureImpactPriceTE; + $priceWithFeatureTI = $featureImpactPriceTI; + } + + if ($priceWithFeatureTI < 0) { + $priceWithFeatureTI = 0; + $priceWithFeatureTE = 0; + } + + $roomTypeWisePricing[$idProduct]['total_price_tax_incl'] += $priceWithFeatureTI; + $roomTypeWisePricing[$idProduct]['total_price_tax_excl'] += $priceWithFeatureTE; + } else { + $roomTypeWisePricing[$idProduct]['total_price_tax_incl'] += $roomTypeWisePricing[$idProduct]['product_price_tax_incl']; + $roomTypeWisePricing[$idProduct]['total_price_tax_excl'] += $roomTypeWisePricing[$idProduct]['product_price_tax_excl']; + } + } + + if ($withAutoRoomservices) { + if (isset($servicesWithTax[$idProduct])) { + foreach($servicesWithTax[$idProduct] as $service) { + $roomTypeWisePricing[$idProduct]['total_price_tax_incl'] += Tools::processPriceRounding($service['price']); + } + } + + if (isset($servicesWithoutTax[$idProduct])) { + foreach($servicesWithoutTax[$idProduct] as $service) { + $roomTypeWisePricing[$idProduct]['total_price_tax_excl'] += Tools::processPriceRounding($service['price']); + } + } + } + + $roomTypeWisePricing[$idProduct]['total_price_tax_excl'] = Tools::processPriceRounding($roomTypeWisePricing[$idProduct]['total_price_tax_excl']); + $roomTypeWisePricing[$idProduct]['total_price_tax_incl'] = Tools::processPriceRounding($roomTypeWisePricing[$idProduct]['total_price_tax_incl']); + } + + Hook::exec('actionRoomTypesTotalPricesModifier', + array( + 'total_prices' => &$roomTypeWisePricing, + 'date_from' => $dateFrom, + 'date_to' => $dateTo, + 'id_currency' => $idCurrency, + 'id_group' => $idGroup, + 'use_reduc' => $useReduc, + ) + ); + + return $roomTypeWisePricing; + } + /** * [getRoomTypeFeaturePricePerDay returns per day feature price od the Room Type] * @param [int] $id_product [id of the product] diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php index 7c80b17e1..19ed65371 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php @@ -167,6 +167,41 @@ class RoomTypeServiceProduct extends ObjectModel return false; } + public static function getAutoAddServicesByIdProducts($idProducts = array(), $dateFrom = null, $dateTo = null, $priceAdditionType = null, $useTax = null, $use_reduc = 1) + { + if ($idProducts) { + $sql = 'SELECT p.`id_product`, `id_element` AS `id_room_type` FROM `'._DB_PREFIX_.'htl_room_type_service_product` rsp + INNER JOIN `'._DB_PREFIX_.'product` p ON (rsp.`id_product` = p.`id_product` AND p.`auto_add_to_cart` = 1) + WHERE p.`active` = 1 AND `id_element` IN( '.implode(', ', $idProducts).') AND `element_type` = '.self::WK_ELEMENT_TYPE_ROOM_TYPE; + if (!is_null($priceAdditionType)) { + $sql .= ' AND p.`price_addition_type` = '.$priceAdditionType; + } + + if ($services = Db::getInstance()->executeS($sql)) { + $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); + $productWiseServices = array(); + foreach($services as $service) { + $service['price'] = $objRoomTypeServiceProductPrice->getServicePrice( + (int)$service['id_product'], + (int)$service['id_room_type'], + 1, + $dateFrom, + $dateTo, + $useTax, + false, + null, + $use_reduc + ); + $productWiseServices[$service['id_room_type']][] = $service; + } + + return $productWiseServices; + } + } + + return false; + } + public function getServiceProductsData($idProductRoomType, $p = 1, $n = 0, $front = false, $available_for_order = 2, $auto_add_to_cart = 0, $subCategory = false, $idLang = false) { if (!$idLang) { diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php index 8feb56940..c3257a1a7 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php @@ -69,23 +69,30 @@ class RoomTypeServiceProductPrice extends ObjectModel public static function getProductRoomTypePriceAndTax($idProduct, $idElement, $elementType) { - if ($result = Db::getInstance()->getRow(' - SELECT spp.`price`, spp.`id_tax_rules_group`, p.`auto_add_to_cart`, p.`price_addition_type` - FROM `'._DB_PREFIX_.'product` p - LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product` sp - ON (sp.`id_product` = p.`id_product`) - LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product_price` spp - ON (spp.`id_product` = sp.`id_product` AND spp.`id_element` = sp.`id_element` AND spp.`element_type` = sp.`element_type`) - WHERE p.`id_product`='.(int)$idProduct. - ' AND sp.`id_element`='.(int)$idElement. - ' AND sp.`element_type`='.(int)$elementType) - ) { - if ($result['auto_add_to_cart'] && $result['price_addition_type'] == Product::PRICE_ADDITION_TYPE_WITH_ROOM) { - // if service is auto add to cart and added in room price, we need to find room type tax rule group - if ($elementType == RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE) { - $result['id_tax_rules_group'] = Product::getIdTaxRulesGroupByIdProduct((int)$idElement); + $cache_key = 'RoomTypeServiceProductPrice::getProductRoomTypePriceAndTax'.$idProduct.'_'.$idElement.'_'.$elementType; + if (!Cache::isStored($cache_key)) { + if ($result = Db::getInstance()->getRow(' + SELECT spp.`price`, spp.`id_tax_rules_group`, p.`auto_add_to_cart`, p.`price_addition_type` + FROM `'._DB_PREFIX_.'product` p + LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product` sp + ON (sp.`id_product` = p.`id_product`) + LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product_price` spp + ON (spp.`id_product` = sp.`id_product` AND spp.`id_element` = sp.`id_element` AND spp.`element_type` = sp.`element_type`) + WHERE p.`id_product`='.(int)$idProduct. + ' AND sp.`id_element`='.(int)$idElement. + ' AND sp.`element_type`='.(int)$elementType) + ) { + if ($result['auto_add_to_cart'] && $result['price_addition_type'] == Product::PRICE_ADDITION_TYPE_WITH_ROOM) { + // if service is auto add to cart and added in room price, we need to find room type tax rule group + if ($elementType == RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE) { + $result['id_tax_rules_group'] = Product::getIdTaxRulesGroupByIdProduct((int)$idElement); + } } } + + Cache::store($cache_key, $result); + } else { + $result = Cache::retrieve($cache_key); } return $result; diff --git a/modules/wkhotelfilterblock/wkhotelfilterblock.php b/modules/wkhotelfilterblock/wkhotelfilterblock.php index 3e628b65c..27d82a4fe 100644 --- a/modules/wkhotelfilterblock/wkhotelfilterblock.php +++ b/modules/wkhotelfilterblock/wkhotelfilterblock.php @@ -198,8 +198,24 @@ class wkhotelfilterblock extends Module $prod_price = array(); if ($room_types) { - foreach ($room_types as $key => $value) { - $prod_price[] = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, HotelBookingDetail::useTax()); + $idProducts = array_column($room_types, 'id_product'); + $productsFeaturePrice = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices( + $idProducts, + $date_from, + $date_to + ); + + $useTax = HotelBookingDetail::useTax(); + if (!($numDays = HotelHelper::getNumberOfDays($date_from, $date_to))) { + $numDays = 1; + } + + foreach ($room_types as $value) { + if ($useTax) { + $prod_price[] = $productsFeaturePrice[$value['id_product']]['total_price_tax_incl'] / $numDays; + } else { + $prod_price[] = $productsFeaturePrice[$value['id_product']]['total_price_tax_excl'] / $numDays; + } } } From 5d6cb9cad598f46ee6b3bd30e98b88683b57584d Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 1 Apr 2025 14:52:57 +0530 Subject: [PATCH 3/5] Added optimization for the price calculation for the room types in the cart --- classes/Cart.php | 16 +++--- .../classes/HotelBookingDetail.php | 2 +- .../classes/HotelCartBookingData.php | 56 ++++++++++++------- .../classes/HotelRoomTypeFeaturePricing.php | 24 +++++--- 4 files changed, 61 insertions(+), 37 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index b0e1c018d..e523441a7 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -733,8 +733,8 @@ class CartCore extends ObjectModel $totalPriceByProductTaxExcl = 0; $priceDisplay = Group::getPriceDisplayMethod(Group::getCurrent()->id); foreach ($roomTypesByIdProduct as $key => $cartRoomInfo) { - $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( - $cartRoomInfo['id_product'], + $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices( + array($cartRoomInfo['id_product']), $cartRoomInfo['date_from'], $cartRoomInfo['date_to'], 0, @@ -744,8 +744,8 @@ class CartCore extends ObjectModel $cartRoomInfo['id_room'], 0 ); - $totalPriceByProductTaxIncl += $roomTotalPrice['total_price_tax_incl']; - $totalPriceByProductTaxExcl += $roomTotalPrice['total_price_tax_excl']; + $totalPriceByProductTaxIncl += $roomTotalPrice[$cartRoomInfo['id_product']]['total_price_tax_incl']; + $totalPriceByProductTaxExcl += $roomTotalPrice[$cartRoomInfo['id_product']]['total_price_tax_excl']; } // Rounding as per configurations @@ -1781,8 +1781,8 @@ class CartCore extends ObjectModel $priceDisplay = Group::getPriceDisplayMethod(Group::getCurrent()->id); foreach ($roomTypesByIdProduct as $key => $cartRoomInfo) { // get the real price of the room type - $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( - $cartRoomInfo['id_product'], + $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices( + array($cartRoomInfo['id_product']), $cartRoomInfo['date_from'], $cartRoomInfo['date_to'], 0, @@ -1793,9 +1793,9 @@ class CartCore extends ObjectModel 0 ); if ($with_taxes) { - $totalPriceByProduct = $roomTotalPrice['total_price_tax_incl']; + $totalPriceByProduct = $roomTotalPrice[$cartRoomInfo['id_product']]['total_price_tax_incl']; } else { - $totalPriceByProduct = $roomTotalPrice['total_price_tax_excl']; + $totalPriceByProduct = $roomTotalPrice[$cartRoomInfo['id_product']]['total_price_tax_excl']; } // If customer has selected advance payment of the cart diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index 328c9b681..d2c68e93c 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -1689,7 +1689,7 @@ class HotelBookingDetail extends ObjectModel $numDays = 1; } $useTax = self::useTax(); - $productsFeaturePriceWithoutReduction = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices($idProducts, $date_from, $date_to, 0, 1, 0); + $productsFeaturePriceWithoutReduction = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices($idProducts, $date_from, $date_to, 0, 0, 0, 0, 0, 1, 0); foreach ($bookingData['rm_data'] as $key => $value) { $product_feature = Product::getFrontFeaturesStatic($this->context->language->id, $value['id_product']); $prod_amen = array(); diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 9f279c76e..0c2da0fa1 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -1331,13 +1331,23 @@ class HotelCartBookingData extends ObjectModel */ public function getCartInfoIdCartIdProduct($id_cart, $id_product, $date_from = false, $date_to = false) { - $sql = 'SELECT * - FROM `'._DB_PREFIX_.'htl_cart_booking_data` - WHERE `id_cart`='.(int) $id_cart.' AND `id_product`='.(int) $id_product; - if ($date_from && $date_to) { - $sql .= ' AND `date_from` = \''.pSQL($date_from).'\' AND `date_to` = \''.pSQL($date_to).'\''; + $cache_key = 'HotelCartBookingData::getCartInfoIdCartIdProduct'.(int)$id_cart.(int)$id_product.($date_from ? strtotime($date_from) : '_').($date_to ? strtotime($date_to) : '_'); + if (!Cache::isStored($cache_key)) { + $sql = 'SELECT * + FROM `'._DB_PREFIX_.'htl_cart_booking_data` + WHERE `id_cart`='.(int) $id_cart.' AND `id_product`='.(int) $id_product; + if ($date_from && $date_to) { + $sql .= ' AND `date_from` = \''.pSQL($date_from).'\' AND `date_to` = \''.pSQL($date_to).'\''; + } + + $res = Db::getInstance()->executeS($sql); + + Cache::store($cache_key, $res); + } else { + $res = Cache::retrieve($cache_key); } - return Db::getInstance()->executeS($sql); + + return $res; } /** @@ -1419,17 +1429,21 @@ class HotelCartBookingData extends ObjectModel $idProducts, $dateFrom, $dateTo, - $idGroup + $idGroup, + $idCart = 0, + $idRoom = 0 ) { $featurePricePriority = Configuration::get('HTL_FEATURE_PRICING_PRIORITY'); if ($featurePricePriority = explode(';', $featurePricePriority)) { if ($featurePrices = Db::getInstance()->executeS( 'SELECT fp.`id_feature_price`, fp.`id_product`, fp.`date_from`, fp.`date_to`, fp.`impact_way`, fp.`is_special_days_exists`, - fp.`date_selection_type`, fp.`special_days`, fp.`impact_type`, fp.`impact_value` + fp.`id_cart`, fp.`id_room`, fp.`date_selection_type`, fp.`special_days`, fp.`impact_type`, fp.`impact_value` FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing` fp'. (Group::isFeatureActive() ? ' INNER JOIN `'._DB_PREFIX_.'htl_room_type_feature_pricing_group` fpg ON (fp.`id_feature_price` = fpg.`id_feature_price` AND fpg.`id_group` = '.(int) $idGroup.')' : '').' - WHERE fp.`id_cart` = 0 AND fp.`id_product` IN('.implode(', ', $idProducts).') AND fp.`active`=1 + WHERE (fp.`id_cart` = 0 '.($idCart ? ' || fp.`id_cart` = '.(int) $idCart: '' ).') + AND (fp.`id_room` = 0 '.($idRoom ? ' || fp.`id_room` = '.(int) $idRoom: '' ).') + AND fp.`id_product` IN('.implode(', ', $idProducts).') AND fp.`active`=1 AND fp.`date_from` <= \''.pSQL($dateTo).'\' AND fp.`date_to` >= \''.pSQL($dateFrom).'\' ' )) { $idProductsWisefeaturePrice = array(); @@ -1686,8 +1700,8 @@ class HotelCartBookingData extends ObjectModel $cartHotelData[$prodKey]['date_diff'][$dateJoin]['children'] = $data_v['children']; $cartHotelData[$prodKey]['date_diff'][$dateJoin]['child_ages'] = json_decode($data_v['child_ages']); - $roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( - $product['id_product'], + $roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices( + array($product['id_product']), $data_v['date_from'], $data_v['date_to'], 0, @@ -1696,8 +1710,8 @@ class HotelCartBookingData extends ObjectModel $context->cart->id_guest, $data_v['id_room'] ); - $roomTypeDateRangePriceWithoutAutoAdd = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( - $product['id_product'], + $roomTypeDateRangePriceWithoutAutoAdd = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices( + array($product['id_product']), $data_v['date_from'], $data_v['date_to'], 0, @@ -1707,8 +1721,8 @@ class HotelCartBookingData extends ObjectModel $data_v['id_room'], 0 ); - $priceWithoutDiscount = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( - $product['id_product'], + $priceWithoutDiscount = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices( + array($product['id_product']), $data_v['date_from'], $data_v['date_to'], 0, @@ -1720,13 +1734,13 @@ class HotelCartBookingData extends ObjectModel 0 ); if (!$price_tax) { - $amount = $roomTypeDateRangePrice['total_price_tax_excl']; - $amountWithoutAutoAdd = $roomTypeDateRangePriceWithoutAutoAdd['total_price_tax_excl']; - $totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_excl']; + $amount = $roomTypeDateRangePrice[$product['id_product']]['total_price_tax_excl']; + $amountWithoutAutoAdd = $roomTypeDateRangePriceWithoutAutoAdd[$product['id_product']]['total_price_tax_excl']; + $totalPriceWithoutDiscount = $priceWithoutDiscount[$product['id_product']]['total_price_tax_excl']; } else { - $amount = $roomTypeDateRangePrice['total_price_tax_incl']; - $amountWithoutAutoAdd = $roomTypeDateRangePriceWithoutAutoAdd['total_price_tax_incl']; - $totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_incl']; + $amount = $roomTypeDateRangePrice[$product['id_product']]['total_price_tax_incl']; + $amountWithoutAutoAdd = $roomTypeDateRangePriceWithoutAutoAdd[$product['id_product']]['total_price_tax_incl']; + $totalPriceWithoutDiscount = $priceWithoutDiscount[$product['id_product']]['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 55513a695..3b0e6afdd 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -793,7 +793,11 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $idProducts = array(), $dateFrom, $dateTo, + $quantity = 0, $idGroup = 0, + $idCart = 0, + $idGuest = 0, + $idRoom = 0, $withAutoRoomservices = 1, $useReduc = 1 ) { @@ -853,9 +857,15 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $idProducts, $dateFrom, $dateTo, - $idGroup + $idGroup, + $idCart, + $idRoom ); + if (!$quantity) { + $quantity = 1; + } + foreach ($idProducts as $idProduct) { for($currentDate = strtotime($dateFrom); $currentDate < strtotime($dateTo); $currentDate += _TIME_1_DAY_) { $featureImpactPriceTI = 0; @@ -916,8 +926,8 @@ class HotelRoomTypeFeaturePricing extends ObjectModel } } - $roomTypeWisePricing[$idProduct]['total_price_tax_excl'] = Tools::processPriceRounding($roomTypeWisePricing[$idProduct]['total_price_tax_excl']); - $roomTypeWisePricing[$idProduct]['total_price_tax_incl'] = Tools::processPriceRounding($roomTypeWisePricing[$idProduct]['total_price_tax_incl']); + $roomTypeWisePricing[$idProduct]['total_price_tax_excl'] = Tools::processPriceRounding($roomTypeWisePricing[$idProduct]['total_price_tax_excl'], $quantity); + $roomTypeWisePricing[$idProduct]['total_price_tax_incl'] = Tools::processPriceRounding($roomTypeWisePricing[$idProduct]['total_price_tax_incl'], $quantity); } Hook::exec('actionRoomTypesTotalPricesModifier', @@ -955,8 +965,8 @@ class HotelRoomTypeFeaturePricing extends ObjectModel ) { $dateFrom = date('Y-m-d H:i:s', strtotime($date_from)); $dateTo = date('Y-m-d H:i:s', strtotime($date_to)); - $totalDurationPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( - $id_product, + $totalDurationPrice = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices( + array($id_product), $dateFrom, $dateTo, 0, @@ -968,8 +978,8 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $use_reduc ); - $totalDurationPriceTI = $totalDurationPrice['total_price_tax_incl']; - $totalDurationPriceTE = $totalDurationPrice['total_price_tax_excl']; + $totalDurationPriceTI = $totalDurationPrice[$id_product]['total_price_tax_incl']; + $totalDurationPriceTE = $totalDurationPrice[$id_product]['total_price_tax_excl']; $numDaysInDuration = HotelHelper::getNumberOfDays($dateFrom, $dateTo); if ($use_tax) { $pricePerDay = $totalDurationPriceTI/$numDaysInDuration; From 2ae8511450573e9f0e8b768f43b39195daa23857 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 15 Apr 2025 16:56:53 +0530 Subject: [PATCH 4/5] Revert the changes made to the function for faster price calculation --- classes/Cart.php | 16 +- .../classes/HotelBookingDetail.php | 26 +-- .../classes/HotelCartBookingData.php | 87 ++------- .../classes/HotelRoomTypeFeaturePricing.php | 166 +----------------- .../classes/RoomTypeServiceProduct.php | 35 ---- .../wkhotelfilterblock/wkhotelfilterblock.php | 20 +-- 6 files changed, 32 insertions(+), 318 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index e523441a7..b0e1c018d 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -733,8 +733,8 @@ class CartCore extends ObjectModel $totalPriceByProductTaxExcl = 0; $priceDisplay = Group::getPriceDisplayMethod(Group::getCurrent()->id); foreach ($roomTypesByIdProduct as $key => $cartRoomInfo) { - $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices( - array($cartRoomInfo['id_product']), + $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $cartRoomInfo['id_product'], $cartRoomInfo['date_from'], $cartRoomInfo['date_to'], 0, @@ -744,8 +744,8 @@ class CartCore extends ObjectModel $cartRoomInfo['id_room'], 0 ); - $totalPriceByProductTaxIncl += $roomTotalPrice[$cartRoomInfo['id_product']]['total_price_tax_incl']; - $totalPriceByProductTaxExcl += $roomTotalPrice[$cartRoomInfo['id_product']]['total_price_tax_excl']; + $totalPriceByProductTaxIncl += $roomTotalPrice['total_price_tax_incl']; + $totalPriceByProductTaxExcl += $roomTotalPrice['total_price_tax_excl']; } // Rounding as per configurations @@ -1781,8 +1781,8 @@ class CartCore extends ObjectModel $priceDisplay = Group::getPriceDisplayMethod(Group::getCurrent()->id); foreach ($roomTypesByIdProduct as $key => $cartRoomInfo) { // get the real price of the room type - $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices( - array($cartRoomInfo['id_product']), + $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $cartRoomInfo['id_product'], $cartRoomInfo['date_from'], $cartRoomInfo['date_to'], 0, @@ -1793,9 +1793,9 @@ class CartCore extends ObjectModel 0 ); if ($with_taxes) { - $totalPriceByProduct = $roomTotalPrice[$cartRoomInfo['id_product']]['total_price_tax_incl']; + $totalPriceByProduct = $roomTotalPrice['total_price_tax_incl']; } else { - $totalPriceByProduct = $roomTotalPrice[$cartRoomInfo['id_product']]['total_price_tax_excl']; + $totalPriceByProduct = $roomTotalPrice['total_price_tax_excl']; } // If customer has selected advance payment of the cart diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index d2c68e93c..1b2a6226b 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -1679,17 +1679,6 @@ class HotelBookingDetail extends ObjectModel if (!$only_search_data) { if (!empty($bookingData)) { - $idProducts = array_keys($bookingData['rm_data']); - $productsFeaturePrice = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices( - $idProducts, - $date_from, - $date_to - ); - if (!($numDays = HotelHelper::getNumberOfDays($date_from, $date_to))) { - $numDays = 1; - } - $useTax = self::useTax(); - $productsFeaturePriceWithoutReduction = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices($idProducts, $date_from, $date_to, 0, 0, 0, 0, 0, 1, 0); foreach ($bookingData['rm_data'] as $key => $value) { $product_feature = Product::getFrontFeaturesStatic($this->context->language->id, $value['id_product']); $prod_amen = array(); @@ -1708,23 +1697,14 @@ class HotelBookingDetail extends ObjectModel continue; } } - if ($useTax) { - $prod_price = $productsFeaturePrice[$value['id_product']]['product_price_tax_incl']; - $productFeaturePrice = $productsFeaturePrice[$value['id_product']]['total_price_tax_incl'] / $numDays; - } else { - $prod_price = $productsFeaturePrice[$value['id_product']]['product_price_tax_excl']; - $productFeaturePrice = $productsFeaturePrice[$value['id_product']]['total_price_tax_excl'] / $numDays; - } + $productFeaturePrice = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax()); if (!empty($price) && ($price['from'] > $productFeaturePrice || $price['to'] < $productFeaturePrice)) { unset($bookingData['rm_data'][$key]); continue; } if (count($value['data']['available'])) { - if ($useTax) { - $productPriceWithoutReduction = $productsFeaturePriceWithoutReduction[$value['id_product']]['total_price_tax_incl'] / $numDays; - } else { - $productPriceWithoutReduction = $productsFeaturePriceWithoutReduction[$value['id_product']]['total_price_tax_excl'] / $numDays; - } + $prod_price = Product::getPriceStatic($value['id_product'], self::useTax()); + $productPriceWithoutReduction = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax(), 0, 0, 0, 0, 1, 0); $cover_image_arr = Product::getCover($value['id_product']); if (!empty($cover_image_arr)) { $cover_img = $this->context->link->getImageLink($value['link_rewrite'], $value['id_product'].'-'.$cover_image_arr['id_image'], 'home_default'); diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 0c2da0fa1..2ad317436 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -1358,7 +1358,7 @@ class HotelCartBookingData extends ObjectModel * @param [int] $id_group [id_group for which price is need (if available for the passed group)] * @return [array|false] [returns array containg info of the feature plan if foung otherwise returns false] */ - public static function getProductFeaturePricePlanByDateByPriority( + public function getProductFeaturePricePlanByDateByPriority( $id_product, $date, $id_group, @@ -1425,67 +1425,6 @@ class HotelCartBookingData extends ObjectModel return false; } - public static function getProductsWiseFeaturePricePlansByDateRangeByPriority( - $idProducts, - $dateFrom, - $dateTo, - $idGroup, - $idCart = 0, - $idRoom = 0 - ) { - $featurePricePriority = Configuration::get('HTL_FEATURE_PRICING_PRIORITY'); - if ($featurePricePriority = explode(';', $featurePricePriority)) { - if ($featurePrices = Db::getInstance()->executeS( - 'SELECT fp.`id_feature_price`, fp.`id_product`, fp.`date_from`, fp.`date_to`, fp.`impact_way`, fp.`is_special_days_exists`, - fp.`id_cart`, fp.`id_room`, fp.`date_selection_type`, fp.`special_days`, fp.`impact_type`, fp.`impact_value` - FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing` fp'. - (Group::isFeatureActive() ? ' INNER JOIN `'._DB_PREFIX_.'htl_room_type_feature_pricing_group` fpg - ON (fp.`id_feature_price` = fpg.`id_feature_price` AND fpg.`id_group` = '.(int) $idGroup.')' : '').' - WHERE (fp.`id_cart` = 0 '.($idCart ? ' || fp.`id_cart` = '.(int) $idCart: '' ).') - AND (fp.`id_room` = 0 '.($idRoom ? ' || fp.`id_room` = '.(int) $idRoom: '' ).') - AND fp.`id_product` IN('.implode(', ', $idProducts).') AND fp.`active`=1 - AND fp.`date_from` <= \''.pSQL($dateTo).'\' AND fp.`date_to` >= \''.pSQL($dateFrom).'\' ' - )) { - $idProductsWisefeaturePrice = array(); - foreach ($featurePrices as $featurePriceKey => $featurePrice) { - for ($currentDate = strtotime($featurePrice['date_from']); $currentDate <= strtotime($featurePrice['date_to']); $currentDate += _TIME_1_DAY_) { - if (!isset($featurePrice['priority'])) { - if ($featurePrice['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { - $featurePrices[$featurePriceKey]['priority'] = $featurePrice['priority'] = array_search('specific_date', $featurePricePriority); - } else if ($featurePrice['is_special_days_exists']) { - $featurePrices[$featurePriceKey]['priority'] = $featurePrice['priority'] = array_search('special_day', $featurePricePriority); - } else if ($featurePrice['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { - $featurePrices[$featurePriceKey]['priority'] = $featurePrice['priority'] = array_search('date_range', $featurePricePriority); - } - } - - if ((int) $featurePrice['is_special_days_exists']) { - $specialDays = json_decode($featurePrice['special_days']); - if (!in_array(strtolower(date('D', $currentDate)), $specialDays)) { - continue; - } - } else if ($featurePrice['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC && $currentDate != strtotime($featurePrice['date_from'])) { - continue; - } - - if (isset($idProductsWisefeaturePrice[$featurePrice['id_product']][$currentDate]) - && $idProductsWisefeaturePrice[$featurePrice['id_product']][$currentDate]['priority'] > $featurePrice['priority'] - ) { - // replacing the feature prices if a feature price of more priority is available. - $idProductsWisefeaturePrice[$featurePrice['id_product']][$currentDate] = $featurePrice; - } else { - $idProductsWisefeaturePrice[$featurePrice['id_product']][$currentDate] = $featurePrice; - } - } - } - - return $idProductsWisefeaturePrice; - } - } - - return false; - } - /** * Returns booking info of the current cart * @param integer $detailed : send 1 for detailedd info and 0 for normal info @@ -1700,8 +1639,8 @@ class HotelCartBookingData extends ObjectModel $cartHotelData[$prodKey]['date_diff'][$dateJoin]['children'] = $data_v['children']; $cartHotelData[$prodKey]['date_diff'][$dateJoin]['child_ages'] = json_decode($data_v['child_ages']); - $roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices( - array($product['id_product']), + $roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $product['id_product'], $data_v['date_from'], $data_v['date_to'], 0, @@ -1710,8 +1649,8 @@ class HotelCartBookingData extends ObjectModel $context->cart->id_guest, $data_v['id_room'] ); - $roomTypeDateRangePriceWithoutAutoAdd = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices( - array($product['id_product']), + $roomTypeDateRangePriceWithoutAutoAdd = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $product['id_product'], $data_v['date_from'], $data_v['date_to'], 0, @@ -1721,8 +1660,8 @@ class HotelCartBookingData extends ObjectModel $data_v['id_room'], 0 ); - $priceWithoutDiscount = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices( - array($product['id_product']), + $priceWithoutDiscount = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $product['id_product'], $data_v['date_from'], $data_v['date_to'], 0, @@ -1734,13 +1673,13 @@ class HotelCartBookingData extends ObjectModel 0 ); if (!$price_tax) { - $amount = $roomTypeDateRangePrice[$product['id_product']]['total_price_tax_excl']; - $amountWithoutAutoAdd = $roomTypeDateRangePriceWithoutAutoAdd[$product['id_product']]['total_price_tax_excl']; - $totalPriceWithoutDiscount = $priceWithoutDiscount[$product['id_product']]['total_price_tax_excl']; + $amount = $roomTypeDateRangePrice['total_price_tax_excl']; + $amountWithoutAutoAdd = $roomTypeDateRangePriceWithoutAutoAdd['total_price_tax_excl']; + $totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_excl']; } else { - $amount = $roomTypeDateRangePrice[$product['id_product']]['total_price_tax_incl']; - $amountWithoutAutoAdd = $roomTypeDateRangePriceWithoutAutoAdd[$product['id_product']]['total_price_tax_incl']; - $totalPriceWithoutDiscount = $priceWithoutDiscount[$product['id_product']]['total_price_tax_incl']; + $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 3b0e6afdd..b62109580 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -671,8 +671,9 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $context = Context::getContext(); $id_currency = Validate::isLoadedObject($context->currency) ? (int)$context->currency->id : (int)Configuration::get('PS_CURRENCY_DEFAULT'); + $hotelCartBookingData = new HotelCartBookingData(); for($currentDate = date('Y-m-d', strtotime($date_from)); $currentDate < date('Y-m-d', strtotime($date_to)); $currentDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate)))) { - if ($use_reduc && ($featurePrice = HotelCartBookingData::getProductFeaturePricePlanByDateByPriority( + if ($use_reduc && ($featurePrice = $hotelCartBookingData->getProductFeaturePricePlanByDateByPriority( $id_product, $currentDate, $id_group, @@ -789,161 +790,6 @@ class HotelRoomTypeFeaturePricing extends ObjectModel return $totalPrice; } - public static function getRoomTypesTotalPrices( - $idProducts = array(), - $dateFrom, - $dateTo, - $quantity = 0, - $idGroup = 0, - $idCart = 0, - $idGuest = 0, - $idRoom = 0, - $withAutoRoomservices = 1, - $useReduc = 1 - ) { - if (!$idProducts) { - return false; - } - - // Initializations - if (!$idGroup) { - $idGroup = (int)Group::getCurrent()->id; - } - - // if dateFrom and dateTo are same then dateTo will be the next date date of dateFrom - if (strtotime($dateFrom) == strtotime($dateTo)) { - $dateTo = date('Y-m-d H:i:s', strtotime('+1 day', strtotime($dateFrom))); - } - - - if ($withAutoRoomservices) { - $servicesWithTax = RoomTypeServiceProduct::getAutoAddServicesByIdProducts( - $idProducts, - $dateFrom, - $dateTo, - Product::PRICE_ADDITION_TYPE_WITH_ROOM, - true, - $useReduc - ); - $servicesWithoutTax = RoomTypeServiceProduct::getAutoAddServicesByIdProducts( - $idProducts, - $dateFrom, - $dateTo, - Product::PRICE_ADDITION_TYPE_WITH_ROOM, - false, - $useReduc - ); - } - - $context = Context::getContext(); - $idCurrency = Validate::isLoadedObject($context->currency) ? (int)$context->currency->id : (int)Configuration::get('PS_CURRENCY_DEFAULT'); - $roomTypeWisePricing = array(); - foreach ($idProducts as $idProduct) { - $productPriceTI = Product::getPriceStatic((int) $idProduct, true, false, 6, null, false, $useReduc); - $productPriceTE = Product::getPriceStatic((int) $idProduct, false, false, 6, null, false, $useReduc); - if ($productPriceTE) { - $roomTypeWisePricing[$idProduct]['tax_rate'] = (($productPriceTI-$productPriceTE)/$productPriceTE)*100; - } else { - $roomTypeWisePricing[$idProduct]['tax_rate'] = 0; - } - - $roomTypeWisePricing[$idProduct]['product_price_tax_incl'] = $productPriceTI; - $roomTypeWisePricing[$idProduct]['product_price_tax_excl'] = $productPriceTE; - $roomTypeWisePricing[$idProduct]['total_price_tax_incl'] = 0; - $roomTypeWisePricing[$idProduct]['total_price_tax_excl'] = 0; - } - - $featurePrices = HotelCartBookingData::getProductsWiseFeaturePricePlansByDateRangeByPriority( - $idProducts, - $dateFrom, - $dateTo, - $idGroup, - $idCart, - $idRoom - ); - - if (!$quantity) { - $quantity = 1; - } - - foreach ($idProducts as $idProduct) { - for($currentDate = strtotime($dateFrom); $currentDate < strtotime($dateTo); $currentDate += _TIME_1_DAY_) { - $featureImpactPriceTI = 0; - $featureImpactPriceTE = 0; - if ($useReduc && isset($featurePrices[$idProduct][$currentDate])) { - $productPriceTI = $roomTypeWisePricing[$idProduct]['product_price_tax_incl']; - $productPriceTE = $roomTypeWisePricing[$idProduct]['product_price_tax_excl']; - $featurePrice = $featurePrices[$idProduct][$currentDate]; - if ($featurePrice['impact_type'] == self::IMPACT_TYPE_PERCENTAGE) { - //percentage - $featureImpactPriceTI = $productPriceTI * ($featurePrice['impact_value'] / 100); - $featureImpactPriceTE = $productPriceTE * ($featurePrice['impact_value'] / 100); - } else { - //Fixed Price - $taxPrice = ($featurePrice['impact_value'] * $roomTypeWisePricing[$idProduct]['tax_rate'])/100; - $featureImpactPriceTE = Tools::convertPrice($featurePrice['impact_value'], $idCurrency); - $featureImpactPriceTI = Tools::convertPrice($featurePrice['impact_value']+$taxPrice, $idCurrency); - } - - if ($featurePrice['impact_way'] == self::IMPACT_WAY_DECREASE) { - // Decrease - $priceWithFeatureTE = ($productPriceTE - $featureImpactPriceTE); - $priceWithFeatureTI = ($productPriceTI - $featureImpactPriceTI); - } elseif ($featurePrice['impact_way'] == self::IMPACT_WAY_INCREASE) { - // Increase - $priceWithFeatureTE = ($productPriceTE + $featureImpactPriceTE); - $priceWithFeatureTI = ($productPriceTI + $featureImpactPriceTI); - } else { - // Fix - $priceWithFeatureTE = $featureImpactPriceTE; - $priceWithFeatureTI = $featureImpactPriceTI; - } - - if ($priceWithFeatureTI < 0) { - $priceWithFeatureTI = 0; - $priceWithFeatureTE = 0; - } - - $roomTypeWisePricing[$idProduct]['total_price_tax_incl'] += $priceWithFeatureTI; - $roomTypeWisePricing[$idProduct]['total_price_tax_excl'] += $priceWithFeatureTE; - } else { - $roomTypeWisePricing[$idProduct]['total_price_tax_incl'] += $roomTypeWisePricing[$idProduct]['product_price_tax_incl']; - $roomTypeWisePricing[$idProduct]['total_price_tax_excl'] += $roomTypeWisePricing[$idProduct]['product_price_tax_excl']; - } - } - - if ($withAutoRoomservices) { - if (isset($servicesWithTax[$idProduct])) { - foreach($servicesWithTax[$idProduct] as $service) { - $roomTypeWisePricing[$idProduct]['total_price_tax_incl'] += Tools::processPriceRounding($service['price']); - } - } - - if (isset($servicesWithoutTax[$idProduct])) { - foreach($servicesWithoutTax[$idProduct] as $service) { - $roomTypeWisePricing[$idProduct]['total_price_tax_excl'] += Tools::processPriceRounding($service['price']); - } - } - } - - $roomTypeWisePricing[$idProduct]['total_price_tax_excl'] = Tools::processPriceRounding($roomTypeWisePricing[$idProduct]['total_price_tax_excl'], $quantity); - $roomTypeWisePricing[$idProduct]['total_price_tax_incl'] = Tools::processPriceRounding($roomTypeWisePricing[$idProduct]['total_price_tax_incl'], $quantity); - } - - Hook::exec('actionRoomTypesTotalPricesModifier', - array( - 'total_prices' => &$roomTypeWisePricing, - 'date_from' => $dateFrom, - 'date_to' => $dateTo, - 'id_currency' => $idCurrency, - 'id_group' => $idGroup, - 'use_reduc' => $useReduc, - ) - ); - - return $roomTypeWisePricing; - } - /** * [getRoomTypeFeaturePricePerDay returns per day feature price od the Room Type] * @param [int] $id_product [id of the product] @@ -965,8 +811,8 @@ class HotelRoomTypeFeaturePricing extends ObjectModel ) { $dateFrom = date('Y-m-d H:i:s', strtotime($date_from)); $dateTo = date('Y-m-d H:i:s', strtotime($date_to)); - $totalDurationPrice = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices( - array($id_product), + $totalDurationPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $id_product, $dateFrom, $dateTo, 0, @@ -978,8 +824,8 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $use_reduc ); - $totalDurationPriceTI = $totalDurationPrice[$id_product]['total_price_tax_incl']; - $totalDurationPriceTE = $totalDurationPrice[$id_product]['total_price_tax_excl']; + $totalDurationPriceTI = $totalDurationPrice['total_price_tax_incl']; + $totalDurationPriceTE = $totalDurationPrice['total_price_tax_excl']; $numDaysInDuration = HotelHelper::getNumberOfDays($dateFrom, $dateTo); if ($use_tax) { $pricePerDay = $totalDurationPriceTI/$numDaysInDuration; diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php index 87a1ac5ca..033222b22 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php @@ -167,41 +167,6 @@ class RoomTypeServiceProduct extends ObjectModel return false; } - public static function getAutoAddServicesByIdProducts($idProducts = array(), $dateFrom = null, $dateTo = null, $priceAdditionType = null, $useTax = null, $use_reduc = 1) - { - if ($idProducts) { - $sql = 'SELECT p.`id_product`, `id_element` AS `id_room_type` FROM `'._DB_PREFIX_.'htl_room_type_service_product` rsp - INNER JOIN `'._DB_PREFIX_.'product` p ON (rsp.`id_product` = p.`id_product` AND p.`auto_add_to_cart` = 1) - WHERE p.`active` = 1 AND `id_element` IN( '.implode(', ', $idProducts).') AND `element_type` = '.self::WK_ELEMENT_TYPE_ROOM_TYPE; - if (!is_null($priceAdditionType)) { - $sql .= ' AND p.`price_addition_type` = '.$priceAdditionType; - } - - if ($services = Db::getInstance()->executeS($sql)) { - $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); - $productWiseServices = array(); - foreach($services as $service) { - $service['price'] = $objRoomTypeServiceProductPrice->getServicePrice( - (int)$service['id_product'], - (int)$service['id_room_type'], - 1, - $dateFrom, - $dateTo, - $useTax, - false, - null, - $use_reduc - ); - $productWiseServices[$service['id_room_type']][] = $service; - } - - return $productWiseServices; - } - } - - return false; - } - public function getServiceProductsData($idProductRoomType, $p = 1, $n = 0, $front = false, $available_for_order = 2, $auto_add_to_cart = 0, $subCategory = false, $idLang = false) { if (!$idLang) { diff --git a/modules/wkhotelfilterblock/wkhotelfilterblock.php b/modules/wkhotelfilterblock/wkhotelfilterblock.php index 27d82a4fe..3e628b65c 100644 --- a/modules/wkhotelfilterblock/wkhotelfilterblock.php +++ b/modules/wkhotelfilterblock/wkhotelfilterblock.php @@ -198,24 +198,8 @@ class wkhotelfilterblock extends Module $prod_price = array(); if ($room_types) { - $idProducts = array_column($room_types, 'id_product'); - $productsFeaturePrice = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices( - $idProducts, - $date_from, - $date_to - ); - - $useTax = HotelBookingDetail::useTax(); - if (!($numDays = HotelHelper::getNumberOfDays($date_from, $date_to))) { - $numDays = 1; - } - - foreach ($room_types as $value) { - if ($useTax) { - $prod_price[] = $productsFeaturePrice[$value['id_product']]['total_price_tax_incl'] / $numDays; - } else { - $prod_price[] = $productsFeaturePrice[$value['id_product']]['total_price_tax_excl'] / $numDays; - } + foreach ($room_types as $key => $value) { + $prod_price[] = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, HotelBookingDetail::useTax()); } } From 87586caf6b10d1fd74a9797b3d1fa2e49b438611 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Thu, 15 May 2025 15:58:04 +0530 Subject: [PATCH 5/5] Updated the cache keys to reduce the risk of key collisions --- classes/Product.php | 2 +- modules/hotelreservationsystem/classes/HotelCartBookingData.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/Product.php b/classes/Product.php index 029dbdc77..19421df19 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -982,7 +982,7 @@ class ProductCore extends ObjectModel public static function isBookingProduct($id_product) { - $cache_key = 'Product::isBookingProduct'.(int)$id_product; + $cache_key = 'Product::isBookingProduct_'.(int)$id_product; if (!Cache::isStored($cache_key)) { $res = Db::getInstance()->getValue(' SELECT `booking_product` FROM `'._DB_PREFIX_.'product` p diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 2a5ae7dc6..23952b89e 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -1331,7 +1331,7 @@ class HotelCartBookingData extends ObjectModel */ public function getCartInfoIdCartIdProduct($id_cart, $id_product, $date_from = false, $date_to = false) { - $cache_key = 'HotelCartBookingData::getCartInfoIdCartIdProduct'.(int)$id_cart.(int)$id_product.($date_from ? strtotime($date_from) : '_').($date_to ? strtotime($date_to) : '_'); + $cache_key = 'HotelCartBookingData::getCartInfoIdCartIdProduct_'.(int)$id_cart.'_'.(int)$id_product.'_'.($date_from ? strtotime($date_from) : 'null').'_'.($date_to ? strtotime($date_to) : 'null'); if (!Cache::isStored($cache_key)) { $sql = 'SELECT * FROM `'._DB_PREFIX_.'htl_cart_booking_data`