From f2513b0f905c857a98dbc1a4c081ca64110050b5 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Wed, 14 Aug 2024 12:35:02 +0530 Subject: [PATCH 01/13] Updated: Optimized data for front search function --- classes/Product.php | 14 ++ .../classes/HotelBookingDetail.php | 156 +++++++----------- .../classes/HotelRoomType.php | 15 +- .../wkhotelfilterblock/wkhotelfilterblock.php | 2 +- .../_partials/room_type_list.tpl | 136 +++++++-------- 5 files changed, 152 insertions(+), 171 deletions(-) diff --git a/classes/Product.php b/classes/Product.php index c47bb1f04..1cf2c0841 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -3494,6 +3494,20 @@ class ProductCore extends ObjectModel return $price; } + public static function getPriceWithoutReductStatic($id_product, $notax = false, $id_product_attribute = false, $decimals = 6, $with_auto_add_services = 0) + { + $price = Product::getPriceStatic((int)$id_product, !$notax, $id_product_attribute, $decimals, null, false, false); + if ($with_auto_add_services) { + if ($services = RoomTypeServiceProduct::getAutoAddServices((int) $id_product, null, null, Product::PRICE_ADDITION_TYPE_WITH_ROOM, !$notax)) { + foreach($services as $service) { + $price += $service['price']; + } + } + } + + return $price; + } + /** * Display price with right format and currency * diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index 77dafade5..8d0bfd22c 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -222,9 +222,6 @@ class HotelBookingDetail extends ObjectModel $params['occupancy'] = array(); } - if (!isset($params['ratting'])) { - $params['ratting'] = -1; - } if (!isset($params['amenities'])) { $params['amenities'] = 0; } @@ -236,6 +233,10 @@ class HotelBookingDetail extends ObjectModel $params['only_search_data'] = 0; } + if (!isset($params['full_detail'])) { + $params['full_detail'] = 0; + } + return $params; } @@ -386,7 +387,7 @@ class HotelBookingDetail extends ObjectModel } // Now we will formate the data after geting search result according to search type - $roomTypesDetail = $objRoomType->getRoomTypeDetailByRoomTypeIds($allowedIdRoomTypes); + $roomTypesDetail = $objRoomType->getRoomTypeDetailByRoomTypeIds($allowedIdRoomTypes, true, $full_detail); if ($roomTypesDetail) { // Formate data for response $finalSearchResponse = array( @@ -401,15 +402,12 @@ class HotelBookingDetail extends ObjectModel $finalSearchResponse['stats']['total_rooms'] += $roomTypeDetail['numberOfRooms']; $idProduct = $roomTypeDetail['id_product']; - $roomTypeSearchData = array( - 'name' => (new Product((int) $idProduct, false, $this->context->cookie->id_lang))->name, - 'id_product' => $idProduct, - 'adults' => $roomTypeDetail['adults'], - 'children' => $roomTypeDetail['children'], - 'max_adults' => $roomTypeDetail['max_adults'], - 'max_children' => $roomTypeDetail['max_children'], - 'max_guests' => $roomTypeDetail['max_guests'], - 'data' => array(), + $roomTypeSearchData = array_merge( + $roomTypeDetail, + array( + 'id_product' => $idProduct, + 'data' => array(), + ) ); if ($search_unavai) { @@ -1500,7 +1498,6 @@ class HotelBookingDetail extends ObjectModel * @param [int] $only_search_data [used for product page and category page for block cart] * @param [int] $adults [] * @param [int] $children [] - * @param [] $ratting [description] * @param [] $amenities [description] * @param [] $price [description] * @param [int] $id_cart [Id of the cart] @@ -1511,10 +1508,6 @@ class HotelBookingDetail extends ObjectModel */ public function dataForFrontSearch($bookingParams) { - // if (Module::isInstalled('productcomments')) { - // require_once _PS_MODULE_DIR_.'productcomments/ProductComment.php'; - // } - $this->context = Context::getContext(); $bookingParams['search_available'] = 1; @@ -1522,6 +1515,7 @@ class HotelBookingDetail extends ObjectModel $bookingParams['search_booked'] = 0; $bookingParams['search_unavai'] = 0; + $bookingParams['full_detail'] = 1; $bookingData = $this->getBookingData($bookingParams); extract($this->getBookingDataParams($bookingParams)); @@ -1531,25 +1525,8 @@ class HotelBookingDetail extends ObjectModel $objRoomType = new HotelRoomType(); foreach ($bookingData['rm_data'] as $key => $value) { - if (empty($value['data']['available'])) { - unset($bookingData['rm_data'][$key]); - } else { - $prod_ratting = 0; - // if (Module::isInstalled('productcomments')) { - // $prod_ratting = ProductComment::getAverageGrade($value['id_product'])['grade']; - // } - // if (empty($prod_ratting)) { - // $prod_ratting = 0; - // } - - // if ($prod_ratting < $ratting && $ratting != -1) { - // unset($bookingData['rm_data'][$key]); - // } else - // { - $product = new Product($value['id_product'], false, $this->context->language->id); - - $product_feature = $product->getFrontFeaturesStatic($this->context->language->id, $value['id_product']); - + if (count($value['data']['available'])) { + $product_feature = Product::getFrontFeaturesStatic($this->context->language->id, $value['id_product']); $prod_amen = array(); if (!empty($amenities) && $amenities) { $prod_amen = $amenities; @@ -1563,72 +1540,51 @@ class HotelBookingDetail extends ObjectModel } if (!empty($prod_amen)) { unset($bookingData['rm_data'][$key]); + continue; } } - - if (empty($prod_amen)) { - $prod_price = Product::getPriceStatic($value['id_product'], self::useTax()); - $productPriceWithoutReduction = $product->getPriceWithoutReduct(!self::useTax()); - $productFeaturePrice = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax()); - $productFeaturePriceWithoutAutoAdd = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax(), 0, 0, 0, 0, 0); - - if (empty($price) || ($price['from'] <= $prod_price && $price['to'] >= $prod_price)) { - $cover_image_arr = $product->getCover($value['id_product']); - - if (!empty($cover_image_arr)) { - $cover_img = $this->context->link->getImageLink($product->link_rewrite, $product->id.'-'.$cover_image_arr['id_image'], 'home_default'); - } else { - $cover_img = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'home_default'); - } - - $room_left = count($bookingData['rm_data'][$key]['data']['available']); - - $rm_dtl = $objRoomType->getRoomTypeInfoByIdProduct($value['id_product']); - - $bookingData['rm_data'][$key]['name'] = $product->name; - $bookingData['rm_data'][$key]['image'] = $cover_img; - $bookingData['rm_data'][$key]['description'] = $product->description_short; - $bookingData['rm_data'][$key]['feature'] = $product_feature; - $bookingData['rm_data'][$key]['price'] = $prod_price; - $bookingData['rm_data'][$key]['feature_price'] = $productFeaturePrice; - $bookingData['rm_data'][$key]['feature_price_withoout_auto_add'] = $productFeaturePriceWithoutAutoAdd; - $bookingData['rm_data'][$key]['price_without_reduction'] = $productPriceWithoutReduction; - $bookingData['rm_data'][$key]['price_without_reduction_with_auto_add'] = $productPriceWithoutReduction + ($productFeaturePrice - $productFeaturePriceWithoutAutoAdd); - $bookingData['rm_data'][$key]['feature_price_diff'] = $bookingData['rm_data'][$key]['price_without_reduction_with_auto_add'] - $productFeaturePrice; - - // if ($room_left <= (int)Configuration::get('WK_ROOM_LEFT_WARNING_NUMBER')) - $bookingData['rm_data'][$key]['room_left'] = $room_left; - - $bookingData['rm_data'][$key]['adults'] = $rm_dtl['adults']; - $bookingData['rm_data'][$key]['children'] = $rm_dtl['children']; - - $bookingData['rm_data'][$key]['ratting'] = $prod_ratting; - // if (Module::isInstalled('productcomments')) { - // $bookingData['rm_data'][$key]['num_review'] = ProductComment::getCommentNumber($value['id_product']); - // } - - // create URL with the parameters from URL - $urlData = array ('date_from' => $date_from, 'date_to' => $date_to); - if (!isset($occupancy)) { - $occupancy = Tools::getValue('occupancy'); - } - if ($occupancy) { - $urlData['occupancy'] = $occupancy; - } - if ($location = Tools::getValue('location')) { - $urlData['location'] = $location; - } - - if (Configuration::get('PS_REWRITING_SETTINGS')) { - $bookingData['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($product).'?'.http_build_query($urlData); - } else { - $bookingData['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($product).'&'.http_build_query($urlData); - } - } else { - unset($bookingData['rm_data'][$key]); - } + $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; + } + + $prod_price = Product::getPriceStatic($value['id_product'], self::useTax()); + $productPriceWithoutReduction = Product::getPriceWithoutReductStatic($value['id_product'], !self::useTax()); + $productFeaturePriceWithoutAutoAdd = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax(), 0, 0, 0, 0, 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'); + } else { + $cover_img = $this->context->link->getImageLink($value['link_rewrite'], $this->context->language->iso_code.'-default', 'home_default'); + } + $bookingData['rm_data'][$key]['image'] = $cover_img; + $bookingData['rm_data'][$key]['feature'] = $product_feature; + $bookingData['rm_data'][$key]['price'] = $prod_price; + $bookingData['rm_data'][$key]['feature_price'] = $productFeaturePrice; + $bookingData['rm_data'][$key]['feature_price_withoout_auto_add'] = $productFeaturePriceWithoutAutoAdd; + $bookingData['rm_data'][$key]['price_without_reduction'] = $productPriceWithoutReduction; + $bookingData['rm_data'][$key]['price_without_reduction_with_auto_add'] = $productPriceWithoutReduction + ($productFeaturePrice - $productFeaturePriceWithoutAutoAdd); + $bookingData['rm_data'][$key]['feature_price_diff'] = $bookingData['rm_data'][$key]['price_without_reduction_with_auto_add'] - $productFeaturePrice; + $bookingData['rm_data'][$key]['room_left'] = count($bookingData['rm_data'][$key]['data']['available']); + + // create URL with the parameters from URL + $urlData = array ('date_from' => $date_from, 'date_to' => $date_to); + if (!isset($occupancy)) { + $occupancy = Tools::getValue('occupancy'); + } + if ($occupancy) { + $urlData['occupancy'] = $occupancy; + } + if ($location = Tools::getValue('location')) { + $urlData['location'] = $location; + } + + if (Configuration::get('PS_REWRITING_SETTINGS')) { + $bookingData['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($value['id_product']).'?'.http_build_query($urlData); + } else { + $bookingData['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($value['id_product']).'&'.http_build_query($urlData); } - // } } } } diff --git a/modules/hotelreservationsystem/classes/HotelRoomType.php b/modules/hotelreservationsystem/classes/HotelRoomType.php index 6c0a80fd4..83ced3591 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomType.php +++ b/modules/hotelreservationsystem/classes/HotelRoomType.php @@ -281,17 +281,26 @@ class HotelRoomType extends ObjectModel /** * @param [int] $roomTypesList: string of idRoomTypes seperated by "," */ - public function getRoomTypeDetailByRoomTypeIds($roomTypesList, $position = true) + public function getRoomTypeDetailByRoomTypeIds($roomTypesList, $position = true, $fullDetail = false, $idLang = false) { - $sql = 'SELECT COUNT(hri.`id`) AS `numberOfRooms`, hrt.`id_product`, `adults`, `children`, `max_adults`, `max_children`, `max_guests`'. - ($position ? ', cp.`position`' : '').' + if (!$idLang) { + $idLang = Context::getContext()->language->id; + } + + $sql = 'SELECT pl.`name`, COUNT(hri.`id`) AS `numberOfRooms`, hrt.`id_product`, `adults`, `children`, `max_adults`, `max_children`, `max_guests` + '.($position ? ', cp.`position`' : '').' + '.($fullDetail ? ', pl.`link_rewrite`, pl.`description_short`' : '').' FROM `'._DB_PREFIX_.'htl_room_type` AS `hrt` INNER JOIN `'._DB_PREFIX_.'htl_room_information` AS `hri` ON (hri.`id_product` = hrt.`id_product`)'; + $sql .= ' INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (hrt.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$idLang.')'; if ($position) { $sql .= ' INNER JOIN `'._DB_PREFIX_.'htl_branch_info` hbi ON (hbi.`id` = hrt.`id_hotel`) INNER JOIN `'._DB_PREFIX_.'category_product` cp ON cp.`id_category` = hbi.`id_category` AND cp.`id_product` = hrt.`id_product`'; } + if ($fullDetail) { + + } $sql .= 'WHERE hrt.`id_product` IN ('.$roomTypesList.') GROUP BY hrt.`id_product`'. diff --git a/modules/wkhotelfilterblock/wkhotelfilterblock.php b/modules/wkhotelfilterblock/wkhotelfilterblock.php index 8aa730452..c4208f16b 100644 --- a/modules/wkhotelfilterblock/wkhotelfilterblock.php +++ b/modules/wkhotelfilterblock/wkhotelfilterblock.php @@ -199,7 +199,7 @@ class wkhotelfilterblock extends Module $prod_price = array(); if ($room_types) { foreach ($room_types as $key => $value) { - $prod_price[] = Product::getPriceStatic($value['id_product'], HotelBookingDetail::useTax()); + $prod_price[] = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, HotelBookingDetail::useTax()); } } diff --git a/themes/hotel-reservation-theme/_partials/room_type_list.tpl b/themes/hotel-reservation-theme/_partials/room_type_list.tpl index b13241709..b14413d7f 100644 --- a/themes/hotel-reservation-theme/_partials/room_type_list.tpl +++ b/themes/hotel-reservation-theme/_partials/room_type_list.tpl @@ -18,87 +18,89 @@ *} {hook h='displayRoomTypeListBefore'} -{if isset($booking_data['rm_data']) && $booking_data['rm_data']} +{if isset($booking_data['stats']) && $booking_data['stats']['num_avail']} {foreach from=$booking_data['rm_data'] key=room_k item=room_v} -
-
- -
-
-

{$room_v['name']|escape:'htmlall':'UTF-8'}

- {if !isset($restricted_country_mode) && !$PS_CATALOG_MODE && !$order_date_restrict} -

$warning_num} style="display:none"{/if}> - {l s='Hurry!'} {$room_v['room_left']|escape:'htmlall':'UTF-8'} {l s='rooms left'} -

- {/if} + {if $room_v['data']['available']|count} +
+
+ -
{$room_v['description']|truncate:190:"":true} {l s='View More'}....
-
+
-
- {if !empty($room_v['feature'])} -

- {foreach from=$room_v['feature'] key=feat_k item=feat_v} - - {/foreach} -

- {/if} -
- -
- {if !isset($restricted_country_mode) && !$PS_CATALOG_MODE && !$order_date_restrict} - -

- {if $room_v['feature_price_diff'] >= 0} - - {displayPrice price = $room_v['price_without_reduction_with_auto_add']|round:2|floatVal} - - {/if} - {if $room_v['feature_price_diff']} - - {displayPrice price = $room_v['feature_price']|round:2|floatVal} - - {/if} - /{l s='Per Night'} -

- {/if} -
+

{$room_v['name']|escape:'htmlall':'UTF-8'}

+ {if !isset($restricted_country_mode) && !$PS_CATALOG_MODE && !$order_date_restrict} +

$warning_num} style="display:none"{/if}> + {l s='Hurry!'} {$room_v['room_left']|escape:'htmlall':'UTF-8'} {l s='rooms left'} +

+ {/if}
-
-
-
{$room_v['max_guests']|escape:'htmlall':'UTF-8'} {l s='Max guests:'}
{$room_v['max_adults']|escape:'htmlall':'UTF-8'} {l s='Adults'}, {$room_v['max_children']|escape:'htmlall':'UTF-8'} {if $room_v['children'] > 1}{l s='Children'}{else}{l s='Child'}{/if}
-
-
-
+
{$room_v['description_short']|truncate:190:"":true} {l s='View More'}....
+
+
+
+ {if !empty($room_v['feature'])} +

+ {foreach from=$room_v['feature'] key=feat_k item=feat_v} + + {/foreach} +

+ {/if} +
+ +
{if !isset($restricted_country_mode) && !$PS_CATALOG_MODE && !$order_date_restrict} - {if isset($occupancy_required_for_booking) && $occupancy_required_for_booking} -
- {include file="./occupancy_field.tpl" room_type_info=$room_v total_available_rooms=$room_v['room_left']} -
- {else} + +

+ {if $room_v['feature_price_diff'] >= 0} + + {displayPrice price = $room_v['price_without_reduction_with_auto_add']|round:2|floatVal} + + {/if} + {if $room_v['feature_price_diff']} + + {displayPrice price = $room_v['feature_price']|round:2|floatVal} + + {/if} + /{l s='Per Night'} +

+ {/if} +
+
+
+
+
{$room_v['max_guests']|escape:'htmlall':'UTF-8'} {l s='Max guests:'}
{$room_v['max_adults']|escape:'htmlall':'UTF-8'} {l s='Adults'}, {$room_v['max_children']|escape:'htmlall':'UTF-8'} {if $room_v['children'] > 1}{l s='Children'}{else}{l s='Child'}{/if}
+
+
+
+ {if !isset($restricted_country_mode) && !$PS_CATALOG_MODE && !$order_date_restrict} + {if isset($occupancy_required_for_booking) && $occupancy_required_for_booking} +
+ {include file="./occupancy_field.tpl" room_type_info=$room_v total_available_rooms=$room_v['room_left']} +
+ {else} +
+ + {include file="./quantity_field.tpl" total_available_rooms=$room_v['room_left']} +
+ {/if}
- - {include file="./quantity_field.tpl" total_available_rooms=$room_v['room_left']} + {l s='Book Now'}
{/if} - - {/if} +
-
+ {/if} {/foreach} {else}
From 3728d59b47cf726ab68e443c844265a4a45b8a65 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Wed, 21 Aug 2024 20:11:09 +0530 Subject: [PATCH 02/13] update data for all search params --- .../classes/HotelBookingDetail.php | 100 +++++++++--------- .../classes/HotelRoomType.php | 3 - 2 files changed, 49 insertions(+), 54 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index 8d0bfd22c..fb7bbde27 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -1525,66 +1525,64 @@ class HotelBookingDetail extends ObjectModel $objRoomType = new HotelRoomType(); foreach ($bookingData['rm_data'] as $key => $value) { - if (count($value['data']['available'])) { - $product_feature = Product::getFrontFeaturesStatic($this->context->language->id, $value['id_product']); - $prod_amen = array(); - if (!empty($amenities) && $amenities) { - $prod_amen = $amenities; - foreach ($product_feature as $a_key => $a_val) { - if (($pa_key = array_search($a_val['id_feature'], $prod_amen)) !== false) { - unset($prod_amen[$pa_key]); - if (empty($prod_amen)) { - break; - } + $product_feature = Product::getFrontFeaturesStatic($this->context->language->id, $value['id_product']); + $prod_amen = array(); + if (!empty($amenities) && $amenities) { + $prod_amen = $amenities; + foreach ($product_feature as $a_key => $a_val) { + if (($pa_key = array_search($a_val['id_feature'], $prod_amen)) !== false) { + unset($prod_amen[$pa_key]); + if (empty($prod_amen)) { + break; } } - if (!empty($prod_amen)) { - unset($bookingData['rm_data'][$key]); - continue; - } } - $productFeaturePrice = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax()); - if (!empty($price) && ($price['from'] > $productFeaturePrice || $price['to'] < $productFeaturePrice)) { + if (!empty($prod_amen)) { unset($bookingData['rm_data'][$key]); continue; } + } + $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; + } - $prod_price = Product::getPriceStatic($value['id_product'], self::useTax()); - $productPriceWithoutReduction = Product::getPriceWithoutReductStatic($value['id_product'], !self::useTax()); - $productFeaturePriceWithoutAutoAdd = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax(), 0, 0, 0, 0, 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'); - } else { - $cover_img = $this->context->link->getImageLink($value['link_rewrite'], $this->context->language->iso_code.'-default', 'home_default'); - } - $bookingData['rm_data'][$key]['image'] = $cover_img; - $bookingData['rm_data'][$key]['feature'] = $product_feature; - $bookingData['rm_data'][$key]['price'] = $prod_price; - $bookingData['rm_data'][$key]['feature_price'] = $productFeaturePrice; - $bookingData['rm_data'][$key]['feature_price_withoout_auto_add'] = $productFeaturePriceWithoutAutoAdd; - $bookingData['rm_data'][$key]['price_without_reduction'] = $productPriceWithoutReduction; - $bookingData['rm_data'][$key]['price_without_reduction_with_auto_add'] = $productPriceWithoutReduction + ($productFeaturePrice - $productFeaturePriceWithoutAutoAdd); - $bookingData['rm_data'][$key]['feature_price_diff'] = $bookingData['rm_data'][$key]['price_without_reduction_with_auto_add'] - $productFeaturePrice; - $bookingData['rm_data'][$key]['room_left'] = count($bookingData['rm_data'][$key]['data']['available']); + $prod_price = Product::getPriceStatic($value['id_product'], self::useTax()); + $productPriceWithoutReduction = Product::getPriceWithoutReductStatic($value['id_product'], !self::useTax()); + $productFeaturePriceWithoutAutoAdd = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax(), 0, 0, 0, 0, 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'); + } else { + $cover_img = $this->context->link->getImageLink($value['link_rewrite'], $this->context->language->iso_code.'-default', 'home_default'); + } + $bookingData['rm_data'][$key]['image'] = $cover_img; + $bookingData['rm_data'][$key]['feature'] = $product_feature; + $bookingData['rm_data'][$key]['price'] = $prod_price; + $bookingData['rm_data'][$key]['feature_price'] = $productFeaturePrice; + $bookingData['rm_data'][$key]['feature_price_withoout_auto_add'] = $productFeaturePriceWithoutAutoAdd; + $bookingData['rm_data'][$key]['price_without_reduction'] = $productPriceWithoutReduction; + $bookingData['rm_data'][$key]['price_without_reduction_with_auto_add'] = $productPriceWithoutReduction + ($productFeaturePrice - $productFeaturePriceWithoutAutoAdd); + $bookingData['rm_data'][$key]['feature_price_diff'] = $bookingData['rm_data'][$key]['price_without_reduction_with_auto_add'] - $productFeaturePrice; + $bookingData['rm_data'][$key]['room_left'] = count($bookingData['rm_data'][$key]['data']['available']); - // create URL with the parameters from URL - $urlData = array ('date_from' => $date_from, 'date_to' => $date_to); - if (!isset($occupancy)) { - $occupancy = Tools::getValue('occupancy'); - } - if ($occupancy) { - $urlData['occupancy'] = $occupancy; - } - if ($location = Tools::getValue('location')) { - $urlData['location'] = $location; - } + // create URL with the parameters from URL + $urlData = array ('date_from' => $date_from, 'date_to' => $date_to); + if (!isset($occupancy)) { + $occupancy = Tools::getValue('occupancy'); + } + if ($occupancy) { + $urlData['occupancy'] = $occupancy; + } + if ($location = Tools::getValue('location')) { + $urlData['location'] = $location; + } - if (Configuration::get('PS_REWRITING_SETTINGS')) { - $bookingData['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($value['id_product']).'?'.http_build_query($urlData); - } else { - $bookingData['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($value['id_product']).'&'.http_build_query($urlData); - } + if (Configuration::get('PS_REWRITING_SETTINGS')) { + $bookingData['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($value['id_product']).'?'.http_build_query($urlData); + } else { + $bookingData['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($value['id_product']).'&'.http_build_query($urlData); } } } diff --git a/modules/hotelreservationsystem/classes/HotelRoomType.php b/modules/hotelreservationsystem/classes/HotelRoomType.php index 83ced3591..9d8bf89e8 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomType.php +++ b/modules/hotelreservationsystem/classes/HotelRoomType.php @@ -298,9 +298,6 @@ class HotelRoomType extends ObjectModel $sql .= ' INNER JOIN `'._DB_PREFIX_.'htl_branch_info` hbi ON (hbi.`id` = hrt.`id_hotel`) INNER JOIN `'._DB_PREFIX_.'category_product` cp ON cp.`id_category` = hbi.`id_category` AND cp.`id_product` = hrt.`id_product`'; } - if ($fullDetail) { - - } $sql .= 'WHERE hrt.`id_product` IN ('.$roomTypesList.') GROUP BY hrt.`id_product`'. From 113b9ebcd535e55242cef01bbe7c7abe3ff61e82 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Thu, 29 Aug 2024 16:31:30 +0530 Subject: [PATCH 03/13] used feature price without reduction for showing price on serch result page --- classes/Product.php | 14 -------------- .../classes/HotelBookingDetail.php | 7 ++----- .../_partials/room_type_list.tpl | 2 +- 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/classes/Product.php b/classes/Product.php index 84d36d0c2..862dd457d 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -3538,20 +3538,6 @@ class ProductCore extends ObjectModel return $price; } - public static function getPriceWithoutReductStatic($id_product, $notax = false, $id_product_attribute = false, $decimals = 6, $with_auto_add_services = 0) - { - $price = Product::getPriceStatic((int)$id_product, !$notax, $id_product_attribute, $decimals, null, false, false); - if ($with_auto_add_services) { - if ($services = RoomTypeServiceProduct::getAutoAddServices((int) $id_product, null, null, Product::PRICE_ADDITION_TYPE_WITH_ROOM, !$notax)) { - foreach($services as $service) { - $price += $service['price']; - } - } - } - - return $price; - } - /** * Display price with right format and currency * diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index 93d6faa63..537aa3412 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -1691,8 +1691,7 @@ class HotelBookingDetail extends ObjectModel } $prod_price = Product::getPriceStatic($value['id_product'], self::useTax()); - $productPriceWithoutReduction = Product::getPriceWithoutReductStatic($value['id_product'], !self::useTax()); - $productFeaturePriceWithoutAutoAdd = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax(), 0, 0, 0, 0, 0); + $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'); @@ -1703,10 +1702,8 @@ class HotelBookingDetail extends ObjectModel $bookingData['rm_data'][$key]['feature'] = $product_feature; $bookingData['rm_data'][$key]['price'] = $prod_price; $bookingData['rm_data'][$key]['feature_price'] = $productFeaturePrice; - $bookingData['rm_data'][$key]['feature_price_withoout_auto_add'] = $productFeaturePriceWithoutAutoAdd; $bookingData['rm_data'][$key]['price_without_reduction'] = $productPriceWithoutReduction; - $bookingData['rm_data'][$key]['price_without_reduction_with_auto_add'] = $productPriceWithoutReduction + ($productFeaturePrice - $productFeaturePriceWithoutAutoAdd); - $bookingData['rm_data'][$key]['feature_price_diff'] = $bookingData['rm_data'][$key]['price_without_reduction_with_auto_add'] - $productFeaturePrice; + $bookingData['rm_data'][$key]['feature_price_diff'] = $productPriceWithoutReduction - $productFeaturePrice; $bookingData['rm_data'][$key]['room_left'] = count($bookingData['rm_data'][$key]['data']['available']); // create URL with the parameters from URL diff --git a/themes/hotel-reservation-theme/_partials/room_type_list.tpl b/themes/hotel-reservation-theme/_partials/room_type_list.tpl index 34beec0fa..f72075d89 100644 --- a/themes/hotel-reservation-theme/_partials/room_type_list.tpl +++ b/themes/hotel-reservation-theme/_partials/room_type_list.tpl @@ -59,7 +59,7 @@

{if $room_v['feature_price_diff'] >= 0} - {displayPrice price = $room_v['price_without_reduction_with_auto_add']|round:2|floatVal} + {displayPrice price = $room_v['price_without_reduction']|round:2|floatVal} {/if} {if $room_v['feature_price_diff']} From 89b445fd5ee417b510c17e4e9946cbe22eb9ef4f Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Thu, 29 Aug 2024 16:41:58 +0530 Subject: [PATCH 04/13] in dataForFrontSearch only assign data when rooms are available --- .../classes/HotelBookingDetail.php | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index 537aa3412..e51d33789 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -1689,39 +1689,40 @@ class HotelBookingDetail extends ObjectModel 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); + $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'); + } else { + $cover_img = $this->context->link->getImageLink($value['link_rewrite'], $this->context->language->iso_code.'-default', 'home_default'); + } + $bookingData['rm_data'][$key]['image'] = $cover_img; + $bookingData['rm_data'][$key]['feature'] = $product_feature; + $bookingData['rm_data'][$key]['price'] = $prod_price; + $bookingData['rm_data'][$key]['feature_price'] = $productFeaturePrice; + $bookingData['rm_data'][$key]['price_without_reduction'] = $productPriceWithoutReduction; + $bookingData['rm_data'][$key]['feature_price_diff'] = $productPriceWithoutReduction - $productFeaturePrice; + $bookingData['rm_data'][$key]['room_left'] = count($bookingData['rm_data'][$key]['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); - $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'); - } else { - $cover_img = $this->context->link->getImageLink($value['link_rewrite'], $this->context->language->iso_code.'-default', 'home_default'); - } - $bookingData['rm_data'][$key]['image'] = $cover_img; - $bookingData['rm_data'][$key]['feature'] = $product_feature; - $bookingData['rm_data'][$key]['price'] = $prod_price; - $bookingData['rm_data'][$key]['feature_price'] = $productFeaturePrice; - $bookingData['rm_data'][$key]['price_without_reduction'] = $productPriceWithoutReduction; - $bookingData['rm_data'][$key]['feature_price_diff'] = $productPriceWithoutReduction - $productFeaturePrice; - $bookingData['rm_data'][$key]['room_left'] = count($bookingData['rm_data'][$key]['data']['available']); + // create URL with the parameters from URL + $urlData = array ('date_from' => $date_from, 'date_to' => $date_to); + if (!isset($occupancy)) { + $occupancy = Tools::getValue('occupancy'); + } + if ($occupancy) { + $urlData['occupancy'] = $occupancy; + } + if ($location = Tools::getValue('location')) { + $urlData['location'] = $location; + } - // create URL with the parameters from URL - $urlData = array ('date_from' => $date_from, 'date_to' => $date_to); - if (!isset($occupancy)) { - $occupancy = Tools::getValue('occupancy'); - } - if ($occupancy) { - $urlData['occupancy'] = $occupancy; - } - if ($location = Tools::getValue('location')) { - $urlData['location'] = $location; - } - - if (Configuration::get('PS_REWRITING_SETTINGS')) { - $bookingData['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($value['id_product']).'?'.http_build_query($urlData); - } else { - $bookingData['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($value['id_product']).'&'.http_build_query($urlData); + if (Configuration::get('PS_REWRITING_SETTINGS')) { + $bookingData['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($value['id_product']).'?'.http_build_query($urlData); + } else { + $bookingData['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($value['id_product']).'&'.http_build_query($urlData); + } } } } From 0df9c3bf12b89400213d426295bca10daf4dbbbc Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Mon, 2 Sep 2024 15:23:31 +0530 Subject: [PATCH 05/13] optimize Availability and rates search API --- .../WebserviceSpecificManagementHotelAri.php | 79 ++++++++++++++++--- 1 file changed, 69 insertions(+), 10 deletions(-) diff --git a/modules/hotelreservationsystem/classes/WebserviceSpecificManagementHotelAri.php b/modules/hotelreservationsystem/classes/WebserviceSpecificManagementHotelAri.php index bc4b33dce..084b97c3d 100644 --- a/modules/hotelreservationsystem/classes/WebserviceSpecificManagementHotelAri.php +++ b/modules/hotelreservationsystem/classes/WebserviceSpecificManagementHotelAri.php @@ -235,6 +235,11 @@ class WebserviceSpecificManagementHotelAri extends ObjectModel implements Webser $dateWiseBreakdown = 1; $datesAriInfo = []; + $bookingParams['search_available'] = 1; + $bookingParams['search_booked'] = 1; + $bookingParams['search_partial'] = 1; + $bookingParams['search_unavai'] = 1; + $ariInfo = $objBookingDtl->getBookingData($bookingParams); $dateFrom = $bookingParams['date_from']; $dateTo = $bookingParams['date_to']; @@ -243,20 +248,73 @@ class WebserviceSpecificManagementHotelAri extends ObjectModel implements Webser $dateBookingParams = $bookingParams; // for a single date there is no use of partial available rooms $dateBookingParams['search_partial'] = 0; + $objCurrency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); - for ($currentDate = $dateFrom; $currentDate < $dateTo; $currentDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate)))) { - $dateBookingParams['date_from'] = $currentDate; - $dateBookingParams['date_to'] = date('Y-m-d', strtotime('+1 day', strtotime($currentDate))); + foreach ($ariInfo['rm_data'] as $key => $roomType) { + $rooms = HotelRoomInformation::getHotelRoomsInfo($ariParams['id_hotel'], $roomType['id_product']); + $ariInfo['rm_data'][$key]['all_rooms'] = array_map(function ($room) { return array('id_room' => $room['id'], 'room_number' => $room['room_num']); }, $rooms); + + } + for ($currentDate = $dateFrom; $currentDate < $dateTo; $currentDate = date('Y-m-d H:i:s', strtotime('+1 day', strtotime($currentDate)))) { + // $dateBookingParams['date_from'] = $currentDate; + // $dateBookingParams['date_to'] = date('Y-m-d', strtotime('+1 day', strtotime($currentDate))); // get inventories for every date - $ariInfo = $objBookingDtl->getBookingData($dateBookingParams); - // append request fields also. will be attached in the response xml - $ariInfo['id_hotel'] = $ariParams['id_hotel']; - $ariInfo['date_from'] = $dateBookingParams['date_from']; - $ariInfo['date_to'] = $dateBookingParams['date_to']; - $ariInfo['num_rooms'] = $totalRooms; + // $ariInfo = $objBookingDtl->getBookingData($dateBookingParams); - $searchAriData[] = $ariInfo; + // append request fields also. will be attached in the response xml + $ariDateInfo['id_hotel'] = $ariParams['id_hotel']; + $ariDateInfo['date_from'] = $currentDate; + $ariDateInfo['date_to'] = date('Y-m-d H:i:s', strtotime('+1 day', strtotime($currentDate))); + $ariDateInfo['currency'] = $objCurrency->iso_code; + $ariDateInfo['total_rooms'] = $totalRooms; + $ariDateInfo['total_available_rooms'] = $totalRooms; + $ariDateInfo['room_types'] = array(); + foreach ($ariInfo['rm_data'] as $roomType) + { + $rooms = array(); + $rooms['available'] = $roomType['all_rooms']; + foreach ($rooms['available'] as $roomKey => $room) { + if (isset($roomType['data']['booked'][$room['id_room']])) { + foreach ($roomType['data']['booked'][$room['id_room']]['detail'] as $bookedDetail) { + if ($bookedDetail['date_to'] > $ariDateInfo['date_from'] && $bookedDetail['date_from'] <= $ariDateInfo['date_to']) { + unset($rooms['available'][$roomKey]); + } + } + } + } + + $roomTypePriceTE = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay( + $roomTypeInfo['id_product'], + $ariInfo['date_from'], + $ariInfo['date_to'], + 0 + ); + + $roomTypePriceTI = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay( + $roomTypeInfo['id_product'], + $ariInfo['date_from'], + $ariInfo['date_to'], + 1 + ); + $totalBookingPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $roomTypeInfo['id_product'], + $ariInfo['date_from'], + $ariInfo['date_to'], + $ariInfo['num_rooms'] + ); + $ariDateInfo['room_types'][] = array( + 'id_room_type' => $roomType->id_product, + 'base_price' => $roomTypePriceTE, + 'base_price_with_tax' => $roomTypePriceTE, + 'total_price' => $totalBookingPrice['total_price_tax_excl'], + 'total_price_with_tax' => $totalBookingPrice['total_price_tax_incl'], + 'name' => $roomType->name, + 'rooms' => array() + ); + } + + $searchAriData[] = $ariDateInfo; } } else { // If api is called for getting ari info for a particular date range $dateWiseBreakdown = 0; @@ -272,6 +330,7 @@ class WebserviceSpecificManagementHotelAri extends ObjectModel implements Webser $searchAriData[] = $ariInfo; } + ddd($searchAriData); // We have to create the json and xml response for request by ourself. So we need to check if data to be sent in xml or json // We have no way to check the output format from parent classed. So we used below code From a7fe0eeff3fd6c765c0687b6de8b4cfe67d36c94 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Wed, 4 Sep 2024 12:49:02 +0530 Subject: [PATCH 06/13] unset roomDetail variable to clear variable reference --- modules/hotelreservationsystem/classes/HotelBookingDetail.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index e51d33789..bfb80f511 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -1193,6 +1193,7 @@ class HotelBookingDetail extends ObjectModel } } unset($datetimeObj); + unset($roomDetail); // If all dates are covered if (!$datesToCover) { From ecdae4122f34cc776256a5c281ded2d4ac01cd56 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Thu, 5 Sep 2024 11:28:00 +0530 Subject: [PATCH 07/13] Optimized: HotelAri webservice --- .../WebserviceSpecificManagementHotelAri.php | 436 ++++++++---------- 1 file changed, 185 insertions(+), 251 deletions(-) diff --git a/modules/hotelreservationsystem/classes/WebserviceSpecificManagementHotelAri.php b/modules/hotelreservationsystem/classes/WebserviceSpecificManagementHotelAri.php index 084b97c3d..8185acf93 100644 --- a/modules/hotelreservationsystem/classes/WebserviceSpecificManagementHotelAri.php +++ b/modules/hotelreservationsystem/classes/WebserviceSpecificManagementHotelAri.php @@ -227,90 +227,133 @@ class WebserviceSpecificManagementHotelAri extends ObjectModel implements Webser // now call the function $objBookingDtl = new HotelBookingDetail(); - $searchAriData = []; // If api is called for getting ari info for all the dates in the provided date range - if (isset($ariParams['date_wise_breakdown']) && $ariParams['date_wise_breakdown'] && $bookingParams['search_available']) { + if (isset($ariParams['date_wise_breakdown']) && $ariParams['date_wise_breakdown']) { $dateWiseBreakdown = 1; - $datesAriInfo = []; + /** + * To generate data for each day, we will need to get data for booked and unavailable dates, s + * so saving the booking_params for generating the response later + */ + $getavail = $bookingParams['search_available']; + $getBooked = $bookingParams['search_booked']; + $getUnavai = $bookingParams['search_unavai']; $bookingParams['search_available'] = 1; $bookingParams['search_booked'] = 1; - $bookingParams['search_partial'] = 1; $bookingParams['search_unavai'] = 1; - $ariInfo = $objBookingDtl->getBookingData($bookingParams); + $bookingData = $objBookingDtl->getBookingData($bookingParams); - $dateFrom = $bookingParams['date_from']; - $dateTo = $bookingParams['date_to']; - - // Lets get data date by date (Every date in the date range) - $dateBookingParams = $bookingParams; - // for a single date there is no use of partial available rooms - $dateBookingParams['search_partial'] = 0; $objCurrency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); - foreach ($ariInfo['rm_data'] as $key => $roomType) { - $rooms = HotelRoomInformation::getHotelRoomsInfo($ariParams['id_hotel'], $roomType['id_product']); - $ariInfo['rm_data'][$key]['all_rooms'] = array_map(function ($room) { return array('id_room' => $room['id'], 'room_number' => $room['room_num']); }, $rooms); - - } - for ($currentDate = $dateFrom; $currentDate < $dateTo; $currentDate = date('Y-m-d H:i:s', strtotime('+1 day', strtotime($currentDate)))) { - // $dateBookingParams['date_from'] = $currentDate; - // $dateBookingParams['date_to'] = date('Y-m-d', strtotime('+1 day', strtotime($currentDate))); - - // get inventories for every date - // $ariInfo = $objBookingDtl->getBookingData($dateBookingParams); - - // append request fields also. will be attached in the response xml - $ariDateInfo['id_hotel'] = $ariParams['id_hotel']; - $ariDateInfo['date_from'] = $currentDate; - $ariDateInfo['date_to'] = date('Y-m-d H:i:s', strtotime('+1 day', strtotime($currentDate))); - $ariDateInfo['currency'] = $objCurrency->iso_code; - $ariDateInfo['total_rooms'] = $totalRooms; - $ariDateInfo['total_available_rooms'] = $totalRooms; - $ariDateInfo['room_types'] = array(); - foreach ($ariInfo['rm_data'] as $roomType) - { - $rooms = array(); - $rooms['available'] = $roomType['all_rooms']; - foreach ($rooms['available'] as $roomKey => $room) { - if (isset($roomType['data']['booked'][$room['id_room']])) { - foreach ($roomType['data']['booked'][$room['id_room']]['detail'] as $bookedDetail) { - if ($bookedDetail['date_to'] > $ariDateInfo['date_from'] && $bookedDetail['date_from'] <= $ariDateInfo['date_to']) { - unset($rooms['available'][$roomKey]); + // saving date wise booked and unavailable rooms to manage available rooms calculation . + $bookedDates = array(); + $unavailableDates = array(); + foreach ($bookingData['rm_data'] as $key => $roomType) { + if ($rooms = HotelRoomInformation::getHotelRoomsInfo($ariParams['id_hotel'], $roomType['id_product'])) { + foreach ($rooms as $room) { + $bookingData['rm_data'][$key]['all_rooms'][$room['id']] = array('id_room' => $room['id'], 'room_number' => $room['room_num']); + } + if (count($roomType['data']['booked'])) { + foreach ($roomType['data']['booked'] as $bookedRoom) { + foreach ($bookedRoom['detail'] as $bookDetail) { + for ($currentDate = date('Y-m-d', strtotime($bookDetail['date_from'])); + $currentDate < date('Y-m-d', strtotime($bookDetail['date_to'])); + $currentDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate))) + ) { + $bookedDates[$currentDate][$roomType['id_product']][$bookedRoom['id_room']] = $bookedRoom['id_room']; } } } } + if (count($roomType['data']['unavailable'])) { + foreach ($roomType['data']['unavailable'] as $unavailableRooms) { + foreach ($unavailableRooms['detail'] as $unavailableDetail) { + for ($currentDate = date('Y-m-d', strtotime($unavailableDetail['date_from'])); + $currentDate < date('Y-m-d', strtotime($unavailableDetail['date_to'])); + $currentDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate))) + ) { + $unavailableDates[$currentDate][$roomType['id_product']][$bookedRoom['id_room']] = $bookedRoom['id_room']; + } + } + } + } + } + } + + // creating ari details for every date + for ($currentDate = $bookingParams['date_from']; $currentDate < $bookingParams['date_to']; $currentDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate)))) { + $nextDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate))); + // append request fields also. will be attached in the response xml + $ariDateInfo['id_hotel'] = $ariParams['id_hotel']; + $ariDateInfo['date_from'] = $currentDate; + $ariDateInfo['date_to'] = $nextDate; + $ariDateInfo['currency'] = $objCurrency->iso_code; + $ariDateInfo['total_rooms'] = 0; + $ariDateInfo['room_types'] = array(); + foreach ($bookingData['rm_data'] as $roomType) + { + if (count($roomType['all_rooms'])) { + $ariDateInfo['total_rooms'] += count($roomType['all_rooms']); + $roomDetail = array(); + + $roomDetail['available'] = $roomType['all_rooms']; + if (isset($bookedDates[$currentDate][$roomType['id_product']])) { + $roomDetail['available'] = array_diff_key($roomDetail['available'], $bookedDates[$currentDate][$roomType['id_product']]); + $roomDetail['booked'] = array_intersect_key($roomType['all_rooms'], $bookedDates[$currentDate][$roomType['id_product']]); + } else { + $roomDetail['booked'] = array(); + } + if (isset($unavailableDates[$currentDate][$roomType['id_product']])) { + $roomDetail['available'] = array_diff_key($roomDetail['available'], $unavailableDates[$currentDate][$roomType['id_product']]); + $roomDetail['unavailable'] = array_intersect_key($roomType['all_rooms'], $unavailableDates[$currentDate][$roomType['id_product']]); + } else { + $roomDetail['unavailable'] = array(); + } + if ($getavail) { + $ariDateInfo[''] += count($roomDetail['available']); + } else { + unset($roomDetail['available']); + } + if ($getUnavai) { + $ariDateInfo['total_unavailable_rooms'] += count($roomDetail['available']); + } else { + unset($roomDetail['unavailable']); + } + if ($getBooked) { + $ariDateInfo['total_booked_rooms'] += count($roomDetail['available']); + } else { + unset($roomDetail['booked']); + } + } $roomTypePriceTE = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay( - $roomTypeInfo['id_product'], - $ariInfo['date_from'], - $ariInfo['date_to'], + $roomType['id_product'], + $currentDate, + date('Y-m-d H:i:s', strtotime('+1 day', strtotime($currentDate))), 0 ); - $roomTypePriceTI = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay( - $roomTypeInfo['id_product'], - $ariInfo['date_from'], - $ariInfo['date_to'], + $roomType['id_product'], + $currentDate, + date('Y-m-d H:i:s', strtotime('+1 day', strtotime($currentDate))), 1 ); $totalBookingPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( - $roomTypeInfo['id_product'], - $ariInfo['date_from'], - $ariInfo['date_to'], - $ariInfo['num_rooms'] + $roomType['id_product'], + $currentDate, + date('Y-m-d H:i:s', strtotime('+1 day', strtotime($currentDate))), + $totalRooms ); $ariDateInfo['room_types'][] = array( - 'id_room_type' => $roomType->id_product, + 'id_room_type' => $roomType['id_product'], 'base_price' => $roomTypePriceTE, - 'base_price_with_tax' => $roomTypePriceTE, + 'base_price_with_tax' => $roomTypePriceTI, 'total_price' => $totalBookingPrice['total_price_tax_excl'], 'total_price_with_tax' => $totalBookingPrice['total_price_tax_incl'], - 'name' => $roomType->name, - 'rooms' => array() + 'name' => $roomType['name'], + 'rooms' => $roomDetail ); } @@ -320,17 +363,59 @@ class WebserviceSpecificManagementHotelAri extends ObjectModel implements Webser $dateWiseBreakdown = 0; // If api is called for getting ari info for a particular date range - $ariInfo = $objBookingDtl->getBookingData($bookingParams); - + $bookingData = $objBookingDtl->getBookingData($bookingParams); // append request fields also. will be attached in the response xml + $ariInfo = array(); $ariInfo['id_hotel'] = $ariParams['id_hotel']; $ariInfo['date_from'] = $bookingParams['date_from']; $ariInfo['date_to'] = $bookingParams['date_to']; - $ariInfo['num_rooms'] = $totalRooms; + $ariInfo['currency'] = $objCurrency->iso_code; + $ariInfo['total_rooms'] = $bookingData['stats']['total_rooms']; + if (isset($bookingData['stats']['num_avail'])) { + $ariInfo['total_available_rooms'] = $bookingData['stats']['num_avail']; + } + if (isset($bookingData['stats']['num_unavail'])) { + $ariInfo['total_unavailable_rooms'] = $bookingData['stats']['num_unavail']; + } + if (isset($bookingData['stats']['num_part_avai'])) { + $ariInfo['total_partial_available_rooms'] = $bookingData['stats']['num_part_avai']; + } + if (isset($bookingData['stats']['num_booked'])) { + $ariInfo['total_booked_rooms'] = $bookingData['stats']['num_booked']; + } + $ariInfo['room_types'] = array(); + foreach ($bookingData['rm_data'] as $roomType) { + $roomTypePriceTE = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay( + $roomType['id_product'], + $currentDate, + date('Y-m-d H:i:s', strtotime('+1 day', strtotime($currentDate))), + 0 + ); + $roomTypePriceTI = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay( + $roomType['id_product'], + $currentDate, + date('Y-m-d H:i:s', strtotime('+1 day', strtotime($currentDate))), + 1 + ); + $totalBookingPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $roomType['id_product'], + $currentDate, + date('Y-m-d H:i:s', strtotime('+1 day', strtotime($currentDate))), + $totalRooms + ); + $ariInfo['room_types'][] = array( + 'id_room_type' => $roomType['id_product'], + 'base_price' => $roomTypePriceTE, + 'base_price_with_tax' => $roomTypePriceTI, + 'total_price' => $totalBookingPrice['total_price_tax_excl'], + 'total_price_with_tax' => $totalBookingPrice['total_price_tax_incl'], + 'name' => $roomType['name'], + 'rooms' => $roomType['data'] + ); + } $searchAriData[] = $ariInfo; } - ddd($searchAriData); // We have to create the json and xml response for request by ourself. So we need to check if data to be sent in xml or json // We have no way to check the output format from parent classed. So we used below code @@ -509,92 +594,70 @@ class WebserviceSpecificManagementHotelAri extends ObjectModel implements Webser $field = array('sqlId' => 'date_to', 'value' => $ariInfo['date_to']); $this->output .= $this->objOutput->getObjectRender()->renderField($field); - $objCurrency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); - $field = array('sqlId' => 'currency', 'value' => $objCurrency->iso_code); + $field = array('sqlId' => 'currency', 'value' => $ariInfo['currency']); $this->output .= $this->objOutput->getObjectRender()->renderField($field); - // check if availability stats are available then only process further - if (isset($ariInfo['stats']) && $ariInfo['stats']) { - $field = array('sqlId' => 'total_rooms', 'value' => $ariInfo['stats']['total_rooms']); + $field = array('sqlId' => 'total_rooms', 'value' => $ariInfo['total_rooms']); + $this->output .= $this->objOutput->getObjectRender()->renderField($field); + + if (isset($ariInfo['total_available_rooms'])) { + $field = array('sqlId' => 'total_available_rooms', 'value' => $ariInfo['total_available_rooms']); $this->output .= $this->objOutput->getObjectRender()->renderField($field); + } - if (isset($ariInfo['stats']['num_avail'])) { - $field = array('sqlId' => 'total_available_rooms', 'value' => $ariInfo['stats']['num_avail']); - $this->output .= $this->objOutput->getObjectRender()->renderField($field); - } + if (isset($ariInfo['total_unavailable_rooms'])) { + $field = array('sqlId' => 'total_unavailable_rooms', 'value' => $ariInfo['total_unavailable_rooms']); + $this->output .= $this->objOutput->getObjectRender()->renderField($field); + } - if (isset($ariInfo['stats']['num_unavail'])) { - $field = array('sqlId' => 'total_unavailable_rooms', 'value' => $ariInfo['stats']['num_unavail']); - $this->output .= $this->objOutput->getObjectRender()->renderField($field); - } + if (isset($ariInfo['total_partial_available_rooms'])) { + $field = array('sqlId' => 'total_partial_available_rooms', 'value' => $ariInfo['total_partial_available_rooms']); + $this->output .= $this->objOutput->getObjectRender()->renderField($field); + } - if (isset($ariInfo['stats']['num_part_avai'])) { - $field = array('sqlId' => 'total_partial_available_rooms', 'value' => $ariInfo['stats']['num_part_avai']); - $this->output .= $this->objOutput->getObjectRender()->renderField($field); - } - - if (isset($ariInfo['stats']['num_booked'])) { - $field = array('sqlId' => 'total_booked_rooms', 'value' => $ariInfo['stats']['num_booked']); - $this->output .= $this->objOutput->getObjectRender()->renderField($field); - } + if (isset($ariInfo['total_booked_rooms'])) { + $field = array('sqlId' => 'total_booked_rooms', 'value' => $ariInfo['total_booked_rooms']); + $this->output .= $this->objOutput->getObjectRender()->renderField($field); } // check if room type data is available then only process further - if (isset($ariInfo['rm_data']) && $ariInfo['rm_data']) { + if (isset($ariInfo['room_types']) && $ariInfo['room_types']) { $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('room_types', array()); - foreach ($ariInfo['rm_data'] as $roomTypeInfo) { - $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('room_type', array(), array('id' => $roomTypeInfo['id_product'], 'xlink_resource' => $this->wsObject->wsUrl.'room_types'.'/'.$roomTypeInfo['id_product'])); + foreach ($ariInfo['room_types'] as $roomTypeInfo) { + $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('room_type', array(), array( + 'id' => $roomTypeInfo['id_product'], + 'xlink_resource' => $this->wsObject->wsUrl.'room_types'.'/'.$roomTypeInfo['id_product'] + )); - $field = array('sqlId' => 'id_room_type', 'value' => $roomTypeInfo['id_product'], 'xlink_resource' => 'room_types'); + $field = array('sqlId' => 'id_room_type', 'value' => $roomTypeInfo['id_room_type'], 'xlink_resource' => 'room_types'); $this->output .= $this->objOutput->getObjectRender()->renderField($field); - // get feature price of room type - $roomTypePrice = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay( - $roomTypeInfo['id_product'], - $ariInfo['date_from'], - $ariInfo['date_to'], - 0 - ); - $field = array('sqlId' => 'base_price', 'value' => $roomTypePrice); + $field = array('sqlId' => 'base_price', 'value' => $roomTypeInfo['base_price']); $this->output .= $this->objOutput->getObjectRender()->renderField($field); - // get feature price of room type - $roomTypePrice = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay( - $roomTypeInfo['id_product'], - $ariInfo['date_from'], - $ariInfo['date_to'], - 1 - ); - $field = array('sqlId' => 'base_price_with_tax', 'value' => $roomTypePrice); + $field = array('sqlId' => 'base_price_with_tax', 'value' => $roomTypeInfo['base_price_with_tax']); $this->output .= $this->objOutput->getObjectRender()->renderField($field); - $totalBookingPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( - $roomTypeInfo['id_product'], - $ariInfo['date_from'], - $ariInfo['date_to'], - $ariInfo['num_rooms'] - ); - $field = array('sqlId' => 'total_price', 'value' => $totalBookingPrice['total_price_tax_excl']); + $field = array('sqlId' => 'total_price', 'value' => $roomTypeInfo['total_price']); $this->output .= $this->objOutput->getObjectRender()->renderField($field); - $totalBookingPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( - $roomTypeInfo['id_product'], - $ariInfo['date_from'], - $ariInfo['date_to'], - $ariInfo['num_rooms'] - ); - $field = array('sqlId' => 'total_price_with_tax', 'value' => $totalBookingPrice['total_price_tax_incl']); + $field = array('sqlId' => 'total_price_with_tax', 'value' => $roomTypeInfo['total_price_with_tax']); $this->output .= $this->objOutput->getObjectRender()->renderField($field); - $objRoomType = new Product($roomTypeInfo['id_product']); + $objRoomType = new Product($roomTypeInfo['id_room_type']); $field = array('sqlId' => 'name', 'value' => $objRoomType->name, 'i18n' => true); $this->output .= $this->objOutput->getObjectRender()->renderField($field); // rooms info of the room type - if (isset($roomTypeInfo['data']) && $roomTypeInfo['data']) { + if ($dateWiseBreakdown) { + $roomTypeKey = 'rooms'; + } else { + $roomTypeKey = 'data'; + } + if (isset($roomTypeInfo['rooms']) && $roomTypeInfo['rooms']) { $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('rooms', array()); - foreach ($roomTypeInfo['data'] as $key => $roomsInfo) { + foreach ($roomTypeInfo['rooms'] as $key => $roomsInfo) { if ($key == 'available') { $nodeRoomAvailability = 'available'; } elseif ($key == 'unavailable') { @@ -635,7 +698,7 @@ class WebserviceSpecificManagementHotelAri extends ObjectModel implements Webser $field = array('sqlId' => 'id_room', 'value' => $roomInfo['id_room']); $this->output .= $this->objOutput->getObjectRender()->renderField($field); - $field = array('sqlId' => 'room_number', 'value' => $roomInfo['room_num']); + $field = array('sqlId' => 'room_number', 'value' => $roomInfo['room_number']); $this->output .= $this->objOutput->getObjectRender()->renderField($field); $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('room', array()); @@ -673,141 +736,12 @@ class WebserviceSpecificManagementHotelAri extends ObjectModel implements Webser // create json for the response of the ari request private function getResponseJson($ariInfoArray, $dateWiseBreakdown = 0) { - $ariFormatted = array(); - if ($ariInfoArray) { - foreach ($ariInfoArray as $ariInfo) { - $dateAriInfo = array(); - $dateAriInfo = array(); - $dateAriInfo['id_hotel'] = $ariInfo['id_hotel']; - $dateAriInfo['date_from'] = $ariInfo['date_from']; - $dateAriInfo['date_to'] = $ariInfo['date_to']; - - $objCurrency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); - $dateAriInfo['currency'] = $objCurrency->iso_code; - - // check if availability stats are available then only process further - if (isset($ariInfo['stats']) && $ariInfo['stats']) { - $dateAriInfo['total_rooms'] = $ariInfo['stats']['total_rooms']; - if (isset($ariInfo['stats']['num_avail'])) { - $dateAriInfo['total_available_rooms'] = $ariInfo['stats']['num_avail']; - } - if (isset($ariInfo['stats']['num_unavail'])) { - $dateAriInfo['total_unavailable_rooms'] = $ariInfo['stats']['num_unavail']; - } - if (isset($ariInfo['stats']['num_part_avai'])) { - $dateAriInfo['total_partial_available_rooms'] = $ariInfo['stats']['num_part_avai']; - } - if (isset($ariInfo['stats']['num_booked'])) { - $dateAriInfo['total_booked_rooms'] = $ariInfo['stats']['num_booked']; - } - } - - // check if room type data is available then only process further - if (isset($ariInfo['rm_data']) && $ariInfo['rm_data']) { - $dateAriInfo['room_types'] = array(); - - foreach ($ariInfo['rm_data'] as $roomTypeIndex => $roomTypeInfo) { - // get feature price of room type - $roomTypePriceTE = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay( - $roomTypeInfo['id_product'], - $ariInfo['date_from'], - $ariInfo['date_to'], - 0 - ); - $roomTypePriceTI = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay( - $roomTypeInfo['id_product'], - $ariInfo['date_from'], - $ariInfo['date_to'], - 1 - ); - $totalBookingPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( - $roomTypeInfo['id_product'], - $ariInfo['date_from'], - $ariInfo['date_to'], - $ariInfo['num_rooms'] - ); - - $dateAriInfo['room_types'][$roomTypeIndex] = array( - 'id_room_type' => $roomTypeInfo['id_product'], - 'base_price' => $roomTypePriceTE, - 'base_price_with_tax' => $roomTypePriceTI, - 'total_price' => $totalBookingPrice['total_price_tax_excl'], - 'total_price_with_tax' => $totalBookingPrice['total_price_tax_incl'] - ); - - $objRoomType = new Product($roomTypeInfo['id_product']); - $dateAriInfo['room_types'][$roomTypeIndex]['name'] = array(); - foreach ($this->objOutput->getObjectRender()->languages as $idLang) { - $dateAriInfo['room_types'][$roomTypeIndex]['name'][] = array( - 'id' => $idLang, - 'value' => $objRoomType->name[$idLang] - ); - } - // if only one lang than do not set name as array and set only value of the room - if (count($dateAriInfo['room_types'][$roomTypeIndex]['name']) == 1) { - $dateAriInfo['room_types'][$roomTypeIndex]['name'] = $dateAriInfo['room_types'][$roomTypeIndex]['name'][0]['value']; - } - - // rooms info of the room type - if (isset($roomTypeInfo['data']) && $roomTypeInfo['data']) { - $dateAriInfo['room_types'][$roomTypeIndex]['rooms'] = array(); - - foreach ($roomTypeInfo['data'] as $key => $roomsInfo) { - $roomsAriInfo = array(); - if ($key == 'available') { - $keyRoomAvailability = 'available'; - } elseif ($key == 'unavailable') { - $keyRoomAvailability = 'unavailable'; - } elseif ($key == 'booked') { - $keyRoomAvailability = 'booked'; - } elseif ($key == 'partially_available') { - $keyRoomAvailability = 'partially_available'; - } - - if ($roomsInfo) { - if ($key == 'partially_available') { - foreach ($roomsInfo as $dateIndex => $partialRoomsInfo) { - if (isset($partialRoomsInfo['rooms']) && $partialRoomsInfo['rooms']) { - $roomsAriInfo[$dateIndex]['date_from'] = $partialRoomsInfo['date_from']; - $roomsAriInfo[$dateIndex]['date_to'] = $partialRoomsInfo['date_to']; - - $roomsAriInfo[$dateIndex]['rooms'] = array(); - foreach ($partialRoomsInfo['rooms'] as $roomInfo) { - $roomDetail = array(); - $roomDetail['id_room'] = $roomInfo['id_room']; - $roomDetail['room_number'] = $roomInfo['room_num']; - - $roomsAriInfo[$dateIndex]['rooms'][] = $roomDetail; - } - } - } - } else { - foreach ($roomsInfo as $roomIndex => $roomInfo) { - $roomsAriInfo[$roomIndex]['id_room'] = $roomInfo['id_room']; - $roomsAriInfo[$roomIndex]['room_number'] = $roomInfo['room_num']; - } - } - } - - $dateAriInfo['room_types'][$roomTypeIndex]['rooms'][$keyRoomAvailability] = array_values($roomsAriInfo); - } - } - - $dateAriInfo['room_types'] = array_values($dateAriInfo['room_types']); - } - } - - $ariFormatted[] = $dateAriInfo; - } - } - - // change the content to the json form for api response $ariReponse = []; if ($dateWiseBreakdown) { // if date wise breakup is requested the parent node will be 'hotel_aris' as per other APIs in QloApps (orders > order) - $ariReponse['hotel_aris'] = array_values($ariFormatted); + $ariReponse['hotel_aris'] = array_values($ariInfoArray); } else { - $ariReponse['hotel_ari'] = $ariFormatted[0]; + $ariReponse['hotel_ari'] = $ariInfoArray[0]; } $this->output .= json_encode($ariReponse); From d5ed2b1110d2eb956119b3175029f7ca50b58564 Mon Sep 17 00:00:00 2001 From: Sumit Panwar Date: Thu, 5 Sep 2024 14:49:51 +0530 Subject: [PATCH 08/13] Updated: Price Rounding process improved in entire QloApps system and Issues in pricing in tables and order edit and reallocation process fixed --- .../controllers/orders/_product_line.tpl | 2 +- ..._extra_services_facilities_tab_content.tpl | 4 +- .../products/additionalfacilities.tpl | 4 +- classes/Cart.php | 190 ++---- classes/PaymentModule.php | 20 +- classes/Tools.php | 21 + classes/order/Order.php | 16 +- classes/order/OrderDetail.php | 18 +- classes/order/OrderSlip.php | 61 +- controllers/admin/AdminCartsController.php | 12 +- controllers/admin/AdminOrdersController.php | 622 +++++++++--------- controllers/front/OrderOpcController.php | 11 +- install/data/xml/configuration.xml | 2 +- .../classes/HotelBookingDemands.php | 51 +- .../classes/HotelBookingDetail.php | 212 +++--- .../classes/HotelCartBookingData.php | 29 +- .../classes/HotelRoomTypeDemandPrice.php | 5 +- .../classes/HotelRoomTypeFeaturePricing.php | 9 +- .../classes/RoomTypeServiceProduct.php | 1 + .../RoomTypeServiceProductCartDetail.php | 258 ++------ .../classes/RoomTypeServiceProductPrice.php | 2 +- .../AdminHotelRoomsBookingController.php | 17 +- .../helpers/view/_partials/booking-rooms.tpl | 2 +- pdf/order-slip.product-tab.tpl | 12 +- 24 files changed, 726 insertions(+), 855 deletions(-) diff --git a/admin/themes/default/template/controllers/orders/_product_line.tpl b/admin/themes/default/template/controllers/orders/_product_line.tpl index 453398fd0..c697a8b6f 100644 --- a/admin/themes/default/template/controllers/orders/_product_line.tpl +++ b/admin/themes/default/template/controllers/orders/_product_line.tpl @@ -124,7 +124,7 @@