diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index 595400dce..278538193 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -124,22 +124,15 @@ public function renderForm() $country = $this->context->country; $smartyVars['defaultCountry'] = $country->name[Configuration::get('PS_LANG_DEFAULT')]; + $idCountry = null; if ($this->display == 'edit') { $idHotel = Tools::getValue('id'); $hotelBranchInfo = new HotelBranchInformation($idHotel); $addressInfo = HotelBranchInformation::getAddress($idHotel); - $statesbycountry = State::getStatesByIdCountry($addressInfo['id_country']); + $idCountry = Tools::getValue('hotel_country', $addressInfo['id_country']); - $states = array(); - if ($statesbycountry) { - foreach ($statesbycountry as $key => $value) { - $states[$key]['id'] = $value['id_state']; - $states[$key]['name'] = $value['name']; - } - } $smartyVars['edit'] = 1; - $smartyVars['state_var'] = $states; $smartyVars['address_info'] = $addressInfo; $smartyVars['hotel_info'] = (array) $hotelBranchInfo; //Hotel Images @@ -175,6 +168,17 @@ public function renderForm() $smartyVars['order_restrict_date_info'] = $restrictDateInfo; } + // manage state option + if ($this->display == 'add') { + $idCountry = Tools::getValue('hotel_country'); + } + + $stateOptions = null; + if ($idCountry) { + $stateOptions = State::getStatesByIdCountry($idCountry); + } + + $smartyVars['state_var'] = $stateOptions; $smartyVars['enabledDisplayMap'] = Configuration::get('WK_GOOGLE_ACTIVE_MAP'); $smartyVars['ps_img_dir'] = _PS_IMG_.'l/'; @@ -600,16 +604,15 @@ public function processStatus() public function ajaxProcessStateByCountryId() { - $states = array(); + $response = array('status' => false, 'states' => array()); if ($idCountry = Tools::getValue('id_country')) { - if ($statesbycountry = State::getStatesByIdCountry($idCountry)) { - foreach ($statesbycountry as $key => $value) { - $states[$key]['id'] = $value['id_state']; - $states[$key]['name'] = $value['name']; - } + if ($states = State::getStatesByIdCountry($idCountry)) { + $response['status'] = true; + $response['states'] = $states; } } - die(json_encode($states)); + + $this->ajaxDie(json_encode($response)); } public function ajaxProcessUploadHotelImages() diff --git a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js index b7e41a498..66a274406 100644 --- a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js +++ b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js @@ -290,9 +290,9 @@ $(document).ready(function() { url: statebycountryurl, success: function(data) { var html = ""; - if (data) { - $.each(data, function(index, value) { - html += ""; + if (data.status && data.states.length) { + $.each(data.states, function(index, value) { + html += ""; }); } $('#hotel_state').append(html); diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl index d9b047f82..212a25a0e 100644 --- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl @@ -160,7 +160,7 @@