From 5847dc2c259be816ff543f064b37bb0b9dad0ee1 Mon Sep 17 00:00:00 2001 From: sumit panwar Date: Mon, 15 Feb 2021 14:21:29 +0530 Subject: [PATCH 1/2] Optimized HotelRoomTypeFeaturePricing class in hotelreservationsystem module --- .../classes/HotelRoomTypeFeaturePricing.php | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index e8e8a3b3a..d4a7c8341 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -82,7 +82,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel public function __construct($id = null, $id_lang = null, $id_shop = null) { $this->moduleInstance = Module::getInstanceByName('hotelreservationsystem'); - parent::__construct($id); + parent::__construct($id, $id_lang, $id_shop); } public function add($autodate = true, $null_values = true) @@ -221,7 +221,7 @@ public static function countFeaturePriceSpecialDays($specialDays, $date_from, $d $date_to = date('Y-m-d', strtotime($date_to)); for($date = $date_from; $date < $date_to; $date = date('Y-m-d', strtotime('+1 day', strtotime($date)))) { - if (in_array(strtolower(Date('D', $date)), $specialDays)) { + if (in_array(Tools::strtolower(Date('D', $date)), $specialDays)) { $specialDaysCount++; } } @@ -321,7 +321,6 @@ public function getHotelRoomTypesRatesAndInventoryByDate($id_hotel, $id_product= */ public function updateRoomTypesFeaturePricesAvailability($featurePricePlans) { - $moduleInstance = new HotelReservationSystem(); $this->errors = array(); if ($featurePricePlans) { if (isset($featurePricePlans['data']) && $featurePricePlans['data']) { @@ -361,7 +360,7 @@ public function updateRoomTypesFeaturePricesAvailability($featurePricePlans) $id_product, $dateFrom, $dateTo, - $type = 'specific_date' + 'specific_date' ); if ($featurePriceExists) { if (!$this->saveFeaturePricePlan($featurePriceExists['id'], 2, $params)) { @@ -378,7 +377,7 @@ public function updateRoomTypesFeaturePricesAvailability($featurePricePlans) $id_product, $dateFrom, $dateTo, - $type='date_range' + 'date_range' ); if ($featurePriceExists) { if ($featurePriceExists['date_from'] == $dateFrom @@ -392,7 +391,7 @@ public function updateRoomTypesFeaturePricesAvailability($featurePricePlans) $this->errors[] = $this->moduleInstance->l('Some error occured while saving Feature Price Plan Info:: Date From : ', 'HotelRoomTypeFeaturePricing').$params['dateFrom'].$this->moduleInstance->l(' Date To : ', 'HotelRoomTypeFeaturePricing').$params['dateFrom'].$this->moduleInstance->l(' Room Type Id : ', 'HotelRoomTypeFeaturePricing').$params['roomTypeId']; } } else { - for($date = $date_from; $date < $date_to; $date = date('Y-m-d', strtotime('+1 day', strtotime($date)))) { + for($date = $dateFrom; $date < $dateTo; $date = date('Y-m-d', strtotime('+1 day', strtotime($date)))) { $currentDate = date('Y-m-d', $date); $nextDayDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate))); $params['dateFrom'] = $currentDate; @@ -402,7 +401,7 @@ public function updateRoomTypesFeaturePricesAvailability($featurePricePlans) $id_product, $currentDate, $nextDayDate, - $type = 'specific_date' + 'specific_date' ); if ($featurePriceExists) { if (!$this->saveFeaturePricePlan( @@ -431,7 +430,6 @@ public function updateRoomTypesFeaturePricesAvailability($featurePricePlans) if (isset($roomTypeRates['inventory'])) { $totalAvailableNotBooked = 0; $totalAvailableRooms = 0; - $totalRooms = 0; $hotelRoomType = new HotelRoomType(); $hotelBookingDetail = new HotelBookingDetail(); $hotelRoomInformation = new HotelRoomInformation(); @@ -458,17 +456,10 @@ public function updateRoomTypesFeaturePricesAvailability($featurePricePlans) ); $countBookedRooms = count($bookedRoomsInfo); if (isset($roomTypeAvailabilityInfo['stats']['total_rooms'])) { - $totalRooms = $roomTypeAvailabilityInfo['stats']['total_rooms']; $totalAvailableNotBooked = $roomTypeAvailabilityInfo['stats']['total_rooms'] - $countBookedRooms; $totalAvailableRooms = $roomTypeAvailabilityInfo['stats']['num_avail']; - $totalAvailableNotBooked = 5; - $totalAvailableRooms = 3; } - /*p($totalAvailableRooms); - p($roomTypeRates['inventory']); - p($totalAvailableNotBooked); - die;*/ if ($roomTypeRates['inventory'] <= $totalAvailableNotBooked) { if ($roomTypeRates['inventory'] < $totalAvailableRooms) { $numDisabledRooms = $totalAvailableRooms - $roomTypeRates['inventory']; @@ -479,7 +470,7 @@ public function updateRoomTypesFeaturePricesAvailability($featurePricePlans) $dateTo ); if ($availableRooms) { - foreach ($availableRooms as $room_k => $room) { + foreach ($availableRooms as $room) { $objRoomDisableDates = new HotelRoomDisableDates(); $params['id_room'] = $room['id']; $params['date_from'] = $dateFrom; @@ -519,7 +510,7 @@ public function updateRoomTypesFeaturePricesAvailability($featurePricePlans) $dateTo ); if ($disabledRooms) { - foreach ($disabledRooms as $k_rm => $disableRoom) { + foreach ($disabledRooms as $disableRoom) { if ($roomsToEnable > 0) { $hotelRoomInformation = new HotelRoomInformation($disableRoom['id']); $objRoomDisableDates = new HotelRoomDisableDates(); @@ -572,13 +563,15 @@ public function updateRoomTypesFeaturePricesAvailability($featurePricePlans) 'HotelRoomTypeFeaturePricing' ); } - die; + + $result = array(); if (count($this->errors)) { $result['status'] = 'failed'; $result['errors'] = $this->errors; } else { $result['status'] = 'success'; } + return $result; } From 51c2c567394a1f23b2b950e2c42e1d5ca7e70760 Mon Sep 17 00:00:00 2001 From: sumit panwar Date: Mon, 15 Feb 2021 14:30:30 +0530 Subject: [PATCH 2/2] static product price removed from HotelRoomTypeFeaturePricing class in hotelreservationsystem module --- .../classes/HotelRoomTypeFeaturePricing.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index d4a7c8341..bffdd1b58 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -332,8 +332,7 @@ public function updateRoomTypesFeaturePricesAvailability($featurePricePlans) $id_product = $key; // feature price rates create and updates if (isset($roomTypeRates['rate'])) { - //$productPriceTE = Product::getPriceStatic((int) $id_product, false); - $productPriceTE = 1000; + $productPriceTE = Product::getPriceStatic((int) $id_product, false); if ($productPriceTE != $roomTypeRates['rate']) { if ($productPriceTE > $roomTypeRates['rate']) { $priceImpactWay = 1;