diff --git a/classes/Cart.php b/classes/Cart.php index fc3fc8c7e..02bbd5c78 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -2308,7 +2308,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 ac8f01e6f..19421df19 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; } /** @@ -973,10 +982,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/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index abf06c453..811bc9b69 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -1688,8 +1688,6 @@ class HotelBookingDetail extends ObjectModel if (!$only_search_data) { if (!empty($bookingData)) { - $objRoomType = new HotelRoomType(); - 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/HotelBranchInformation.php b/modules/hotelreservationsystem/classes/HotelBranchInformation.php index 172ed2e61..3314010bb 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 b944b78f8..cd14d0976 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -1344,13 +1344,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) : 'null').'_'.($date_to ? strtotime($date_to) : 'null'); + 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; } /** 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/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 d9005e630..7dc8ecb8d 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -832,8 +832,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 c01451080..2c178919f 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php @@ -186,7 +186,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 b2a6123b5..d3056058a 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php @@ -281,10 +281,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; diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php index ffb137c2f..bdb61f1b9 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;