From 10c69e6f760237f0773842dfcd8bb1b33ce5d88f Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Thu, 9 Mar 2023 20:48:19 +0530 Subject: [PATCH] added primary hotel for price calculation --- classes/Cart.php | 3 ++ classes/Product.php | 31 +++++++++++----- .../classes/HotelHelper.php | 2 + .../admin/AdminAddHotelController.php | 37 +++++++++++++++++++ .../AdminHotelGeneralSettingsController.php | 10 +++++ .../views/js/HotelReservationAdmin.js | 24 ++++++++++++ 6 files changed, 98 insertions(+), 9 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index fe5e5a1a1..9c2c1051d 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -3036,6 +3036,9 @@ class CartCore extends ObjectModel } else if ($id_hotel) { $addressInfo = HotelBranchInformation::getAddress($id_hotel); return $addressInfo['id_address']; + } else { + // provide an address for service product. + // for now we do not have an address associated with the service product } return false; } diff --git a/classes/Product.php b/classes/Product.php index 33d169e23..4c712e970 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -3041,17 +3041,30 @@ class ProductCore extends ObjectModel $id_state = 0; $zipcode = 0; - if ($id_address) { - $address_infos = Address::getCountryAndState($id_address); - } else { - // if ($id_roomtype) { - // $address_infos = Address::getCountryAndState(Cart::getIdAddressForTaxCalculation($id_roomtype)); - // } else { - $address_infos = Address::getCountryAndState(Cart::getIdAddressForTaxCalculation($id_product)); - // } + if (!$id_address) { + if (!Product::isBookingProduct($id_product)) { + if ($id_roomtype) { + // if room type is provided with product then we know that the service product price should be calculated accroding to roomt type + $id_address = Cart::getIdAddressForTaxCalculation($id_roomtype); + } + } else { + $id_address = Cart::getIdAddressForTaxCalculation($id_product); + } } - if ($address_infos['id_country']) { + if (!$id_address) { + if ($primaryHotel = ConfigurationCore::get('WK_PRIMARY_HOTEL')) { + if ($address = HotelBranchInformation::getAddress($primaryHotel)) { + $address_infos['id_country'] = $address['id_country']; + $address_infos['id_state'] = $address['id_state']; + $address_infos['postcode'] = $address['postcode']; + } + } + } elseif ($id_address) { + $address_infos = Address::getCountryAndState($id_address); + } + + if (isset($address_infos['id_country'])) { $id_country = (int)$address_infos['id_country']; $id_state = (int)$address_infos['id_state']; $zipcode = $address_infos['postcode']; diff --git a/modules/hotelreservationsystem/classes/HotelHelper.php b/modules/hotelreservationsystem/classes/HotelHelper.php index 7234b8370..b1f5fba4f 100644 --- a/modules/hotelreservationsystem/classes/HotelHelper.php +++ b/modules/hotelreservationsystem/classes/HotelHelper.php @@ -401,6 +401,8 @@ class HotelHelper $obj_hotel_info->id_category = $cat_hotel; $obj_hotel_info->save(); } + // save dummy hotel as primary hotel + Configuration::updateValue('WK_PRIMARY_HOTEL', $htl_id); return $htl_id; } diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index 57e616fce..698330cc3 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -422,6 +422,18 @@ class AdminAddHotelController extends ModuleAdminController if ($newIdHotel = $objHotelBranch->id) { + if ($primaryHotelId = Configuration::get('WK_PRIMARY_HOTEL')) { + if ($primaryHotelId == $objHotelBranch->id && !$objHotelBranch->active) { + $hotels = $objHotelBranch->hotelBranchesInfo(false, 1); + if (!empty($hotel = array_shift($hotels))) { + Configuration::updateValue('WK_PRIMARY_HOTEL', $objHotelBranch['id']); + } else { + $newPrimaryHotelId = Configuration::updateValue('WK_PRIMARY_HOTEL', 0); + } + } + } else if ($objHotelBranch->active) { + Configuration::updateValue('WK_PRIMARY_HOTEL', $objHotelBranch->id); + } // getHotel address if ($idHotelAddress = $objHotelBranch->getHotelIdAddress()) { $objAddress = new Address($idHotelAddress); @@ -559,6 +571,29 @@ class AdminAddHotelController extends ModuleAdminController $this->display = 'add'; } } + public function processStatus() + { + parent::processStatus(); + if (empty($this->errors)) { + if (Validate::isLoadedObject($objHotelBranch = new HotelBranchInformation(Tools::getValue('id')))) { + if ($primaryHotelId = Configuration::get('WK_PRIMARY_HOTEL')) { + if ($primaryHotelId == $objHotelBranch->id && !$objHotelBranch->active) { + $hotels = $objHotelBranch->hotelBranchesInfo(false, 1); + if (!empty($hotel = array_shift($hotels))) { + Configuration::updateValue('WK_PRIMARY_HOTEL', $hotel['id']); + } else { + $newPrimaryHotelId = Configuration::updateValue('WK_PRIMARY_HOTEL', 0); + } + } + } else { + $hotels = $objHotelBranch->hotelBranchesInfo(false, 1); + if (!empty($hotel = array_shift($hotels))) { + Configuration::updateValue('WK_PRIMARY_HOTEL', $hotel['id']); + } + } + } + } + } public function ajaxProcessStateByCountryId() { @@ -686,6 +721,8 @@ class AdminAddHotelController extends ModuleAdminController 'filesizeError' => $this->l('File exceeds maximum size.'), 'maxSizeAllowed' => Tools::getMaxUploadSize(), 'sortRowsUrl' => $this->context->link->getAdminLink('AdminAddHotel'), + 'primaryHotelId' => Configuration::get('WK_PRIMARY_HOTEL'), + 'disableHotelMsg' => $this->l('Primary hotel for website will be updated to first available active hotel.'), ) ); // GOOGLE MAP diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php index 96280681b..e51f9911f 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php @@ -35,6 +35,9 @@ class AdminHotelGeneralSettingsController extends ModuleAdminController if (!$hotelsInfo = $objHotelInfo->hotelBranchesInfo(false, 1)) { $hotelsInfo = array(); } + foreach ($hotelsInfo as &$hotel) { + $hotel['name'] = $hotel['hotel_name']; + } $hotelNameDisable = (count($hotelsInfo) > 1 ? true : false); $locationDisable = ((count($hotelsInfo) < 2) && !Configuration::get('WK_HOTEL_NAME_ENABLE')) ? true : false; $this->fields_options = array( @@ -142,6 +145,13 @@ class AdminHotelGeneralSettingsController extends ModuleAdminController 'hint' => $this->l('The year when your hotel site was launched.'), 'type' => 'text', ), + 'WK_PRIMARY_HOTEL' => array( + 'title' => $this->l('Primary hotel'), + 'hint' => $this->l('Primary hotel is used to default address for your business. The hotel address will be considered as your registered business address.'), + 'type' => 'select', + 'identifier' => 'id', + 'list' => $hotelsInfo, + ), 'WK_HTL_CHAIN_NAME' => array( 'title' => $this->l('Hotel Name'), 'type' => 'textLang', diff --git a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js index 0c60a8389..b7e41a498 100644 --- a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js +++ b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js @@ -227,6 +227,30 @@ function initGoogleMaps() { $(document).ready(function() { //For Add Hotels + + // hotel status change + $("#form-htl_branch_info a.list-action-enable.action-enabled").on('click', function(e) { + let id_hotel = $(this).closest('tr').find('.row-selector input').val(); + if (id_hotel == primaryHotelId) { + if (!confirm(disableHotelMsg)) { + e.preventDefault(); + e.stopImmediatePropagation(); + return false; + } + } + }); + $("form#htl_branch_info_form").on('submit', function(e) { + let id_hotel = $(this).find('#id-hotel').val(); + let enable = $(this).find('[name="ENABLE_HOTEL"]:checked').val(); + if (id_hotel == primaryHotelId && !parseInt(enable)) { + if (!confirm(disableHotelMsg)) { + e.preventDefault(); + e.stopImmediatePropagation(); + return false; + } + } + }); + // delete hotel image $('.deleteHtlImage').on('click', function(){ var imgId = $(this).attr('id_htl_img');