Optimized: Functions and removed unnecessary object initialization to reduce overhead.

Optimized: Functions and removed unnecessary object initialization to reduce overhead.
This commit is contained in:
Rohit Jain
2025-05-15 20:05:13 +05:30
committed by GitHub
11 changed files with 104 additions and 52 deletions

View File

@@ -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) {

View File

@@ -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()

View File

@@ -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();

View File

@@ -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;
}
/**

View File

@@ -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;
}
/**

View File

@@ -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*/

View File

@@ -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;
}
/**

View File

@@ -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 {

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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;