From e457cafbc9e8a325df3dd950ad65fa2f9be555b8 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Wed, 8 May 2024 15:44:45 +0530 Subject: [PATCH 1/3] Added: Hotel wise search in the ajax_products_listadded hotel select option on the admin Hotel room module setting controller and hotel and room type name in the render list, also added hotel wise restriction on the edit, delete and add --- admin/ajax_products_list.php | 35 ++++++--- .../AdminHotelRoomModuleSettingController.php | 77 ++++++++++++++++--- .../views/js/WkHotelRoomBlockAdmin.js | 49 +++++++----- 3 files changed, 122 insertions(+), 39 deletions(-) diff --git a/admin/ajax_products_list.php b/admin/ajax_products_list.php index 98f9647cb..2971bdd42 100644 --- a/admin/ajax_products_list.php +++ b/admin/ajax_products_list.php @@ -60,22 +60,39 @@ $exclude_packs = (bool)Tools::getValue('exclude_packs', true); $bookingProduct = (int) Tools::getValue('booking_product'); +$idHotel = (int) Tools::getValue('id_hotel'); + $context = Context::getContext(); -$sql = 'SELECT p.`id_product`, pl.`link_rewrite`, p.`reference`, pl.`name`, image_shop.`id_image` id_image, il.`legend`, p.`cache_default_attribute` - FROM `'._DB_PREFIX_.'product` p - '.Shop::addSqlAssociation('product', 'p').' - LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.id_product = p.id_product AND pl.id_lang = '.(int)$context->language->id.Shop::addSqlRestrictionOnLang('pl').') +$sqlSelect = 'SELECT p.`id_product`, pl.`link_rewrite`, p.`reference`, pl.`name`, image_shop.`id_image` id_image, il.`legend`, p.`cache_default_attribute`'; + +$sqlFrom = ' FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p'); + +$sqlJoin =' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = '.(int) $context->language->id.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop - ON (image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop='.(int)$context->shop->id.') - LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$context->language->id.') - WHERE (pl.name LIKE \'%'.pSQL($query).'%\' OR p.reference LIKE \'%'.pSQL($query).'%\')'. + ON (image_shop.`id_product` = p.`id_product` AND image_shop.`cover`=1 AND image_shop.`id_shop`='.(int) $context->shop->id.') + LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int) $context->language->id.')'; + +$sqlWhere = ' WHERE (pl.name LIKE \'%'.pSQL($query).'%\' OR p.reference LIKE \'%'.pSQL($query).'%\')'. (!empty($excludeIds) ? ' AND p.id_product NOT IN ('.$excludeIds.') ' : ' '). (!empty($excludePackItself) ? ' AND p.id_product <> '.$excludePackItself.' ' : ' '). ($excludeVirtuals ? 'AND NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'product_download` pd WHERE (pd.id_product = p.id_product))' : ''). ($exclude_packs ? 'AND (p.cache_is_pack IS NULL OR p.cache_is_pack = 0)' : ''). - ($bookingProduct ? 'AND p.`booking_product` = '.(int) $bookingProduct : ''). - ' GROUP BY p.id_product'; + ($bookingProduct ? 'AND p.`booking_product` = '.(int) $bookingProduct : ''); + +$sqlGroupBy = ' GROUP BY p.id_product'; + +if ($idHotel && $bookingProduct) { + // To get hotel info for the booking product only + $sqlSelect .= ', hbil.`hotel_name`, hbil.`id` AS id_hotel '; + $sqlJoin .= ' LEFT JOIN `'._DB_PREFIX_.'htl_room_type` hrt + ON hrt.`id_product` = p.`id_product` + LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbil + ON pl.`id_lang` = hbil.`id_lang` AND hbil.`id` = hrt.`id_hotel`'; + $sqlWhere .= ' AND hbil.`id`='.(int) $idHotel ; +} + +$sql = $sqlSelect.' '.$sqlFrom.' '.$sqlJoin.' '.$sqlWhere.' '.$sqlGroupBy; $items = Db::getInstance()->executeS($sql); diff --git a/modules/wkhotelroom/controllers/admin/AdminHotelRoomModuleSettingController.php b/modules/wkhotelroom/controllers/admin/AdminHotelRoomModuleSettingController.php index 5e54ca3db..749e27720 100644 --- a/modules/wkhotelroom/controllers/admin/AdminHotelRoomModuleSettingController.php +++ b/modules/wkhotelroom/controllers/admin/AdminHotelRoomModuleSettingController.php @@ -29,11 +29,20 @@ class AdminHotelRoomModuleSettingController extends ModuleAdminController $this->bootstrap = true; $this->context = Context::getContext(); + $this->_select = ' pl.`name`, hbil.`hotel_name` '; + + $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl + ON (pl.`id_product` = a.`id_product` AND pl.id_lang = '.(int) $this->context->language->id.')'; + $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'htl_room_type` hrt + ON (hrt.`id_product` = a.`id_product`)'; + $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbil + ON (hrt.`id_hotel` = hbil.`id` AND hbil.`id_lang` = pl.`id_lang`)'; + $this->fields_options = array( 'global' => array( - 'title' => $this->l('Hotel Room Display Setting'), - 'icon' => 'icon-cogs', - 'fields' => array( + 'title' => $this->l('Hotel Room Display Setting'), + 'icon' => 'icon-cogs', + 'fields' => array( 'HOTEL_ROOM_DISPLAY_HEADING' => array( 'title' => $this->l('Hotel Room Block Title'), 'type' => 'textLang', @@ -73,6 +82,16 @@ class AdminHotelRoomModuleSettingController extends ModuleAdminController 'search' => false, 'callback' => 'getProductImage', ), + 'hotel_name' => array( + 'title' => $this->l('Hotel'), + 'align' => 'center', + 'orderby' => false, + ), + 'name' => array( + 'title' => $this->l('Room Type'), + 'align' => 'center', + 'orderby' => false, + ), 'active' => array( 'title' => $this->l('Active'), 'align' => 'center', @@ -109,6 +128,27 @@ class AdminHotelRoomModuleSettingController extends ModuleAdminController $this->identifier = 'id_room_block'; parent::__construct(); + $this->hotelList = HotelBranchInformation::getProfileAccessedHotels( + $this->context->employee->id_profile, + 1 + ); + $objHotelRoomType = new HotelRoomType(); + if ($this->loadObject(true) + && $this->object->id + && ($roomInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct((int) $this->object->id_product)) + ) { + $hasHotelAccess = false; + foreach ($this->hotelList as $hotel) { + if ($hotel['id_hotel'] == $roomInfo['id_hotel']) { + $hasHotelAccess = true; + } + } + + if (!$hasHotelAccess) { + $this->tabAccess['edit'] = 0; + $this->tabAccess['view'] = 0; + } + } } public function getProductImage($idProduct) @@ -152,29 +192,33 @@ class AdminHotelRoomModuleSettingController extends ModuleAdminController public function renderForm() { - if (!($obj = $this->loadObject(true))) { + if (!($this->loadObject(true))) { return; } - $productName = $idProduct = false; - - if ($this->display == 'edit') { - $objRoomBlock = new WkHotelRoomDisplay($obj->id); - $idProduct = $objRoomBlock->id_product; + $productName = false; + if ($idProduct = $this->object->id_product) { $product = new Product($idProduct, false, Configuration::get('PS_LANG_DEFAULT')); $productName = $product->name; + $objHotelRoomType = new HotelRoomType(); + if ($roomInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct((int) $product->id)) { + $this->fields_value['id_hotel'] = $roomInfo['id_hotel']; + } } $this->context->smarty->assign( array( 'productName' => $productName, - 'idProduct' => $idProduct, + 'idProduct' => $idProduct ) ); $html = $this->context->smarty->fetch( _PS_MODULE_DIR_.$this->module->name. '/views/templates/admin/hotel_room/product_search_block.tpl' ); + if (empty($this->hotelList)) { + $this->warnings[] = $this->l('You do not have access to any hotel to search for the room types.'); + } $this->fields_form = array( 'legend' => array( @@ -182,6 +226,19 @@ class AdminHotelRoomModuleSettingController extends ModuleAdminController 'icon' => 'icon-globe' ), 'input' => array( + array( + 'type' => 'select', + 'label' => $this->l('Select hotel'), + 'name' => 'id_hotel', + 'required' => true, + 'class' => 'chosen', + 'options' => array( + 'query' => $this->hotelList, + 'id' => 'id_hotel', + 'name' => 'hotel_name' + ), + 'hint' => $this->l('Select the hotel.'), + ), array( 'label' => $this->l('Search Room Type'), 'type' => 'html', diff --git a/modules/wkhotelroom/views/js/WkHotelRoomBlockAdmin.js b/modules/wkhotelroom/views/js/WkHotelRoomBlockAdmin.js index 7aee0d3a2..6fed1a26d 100644 --- a/modules/wkhotelroom/views/js/WkHotelRoomBlockAdmin.js +++ b/modules/wkhotelroom/views/js/WkHotelRoomBlockAdmin.js @@ -32,27 +32,31 @@ $(document).ready(function() { var word = $(this).val(); var d = new Date(); var n = d.getTime(); - trigger_ajax = $.ajax({ - url: "ajax_products_list.php", - dataType: 'json', - data: { - q: word, - _: n, - booking_product: '1', - }, - success: function(result) { - if (result) { - var html = ''; - $.each(result, function(key, value) { - html += '
  • ' + value.name + '
  • '; - }); - suggestion_ul.html(html).show(); - } else { - suggestion_ul.empty().hide(); - suggestion_ul.siblings("input#id_product").val(null); + var id_hotel = parseInt($('#id_hotel').val()); + if (!isNaN(id_hotel)) { + trigger_ajax = $.ajax({ + url: "ajax_products_list.php", + dataType: 'json', + data: { + q: word, + _: n, + booking_product: '1', + id_hotel: id_hotel + }, + success: function(result) { + if (result) { + var html = ''; + $.each(result, function(key, value) { + html += '
  • ' + value.id+ '. '+ value.name + '
  • '; + }); + suggestion_ul.html(html).show(); + } else { + suggestion_ul.empty().hide(); + suggestion_ul.siblings("input#id_product").val(null); + } } - } - }); + }); + } } } }); @@ -73,4 +77,9 @@ $(document).ready(function() { $('ul.prod_suggest_ul').empty().hide(); } }); + $(document).on('change', '#id_hotel', function () { + // resetting the fields on hotel change + $('#id_product').val(''); + $('#productName').val(''); + }); }); \ No newline at end of file From 31caba7b2cfbe3486a4edd51d62d18e1847d45c1 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 17 May 2024 16:42:11 +0530 Subject: [PATCH 2/3] Updated: The new room block form will not be displayed if there is no hotel available --- .../AdminHotelRoomModuleSettingController.php | 46 ++++++++----------- .../views/js/WkHotelRoomBlockAdmin.js | 2 +- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/modules/wkhotelroom/controllers/admin/AdminHotelRoomModuleSettingController.php b/modules/wkhotelroom/controllers/admin/AdminHotelRoomModuleSettingController.php index 749e27720..f6242897d 100644 --- a/modules/wkhotelroom/controllers/admin/AdminHotelRoomModuleSettingController.php +++ b/modules/wkhotelroom/controllers/admin/AdminHotelRoomModuleSettingController.php @@ -82,13 +82,13 @@ class AdminHotelRoomModuleSettingController extends ModuleAdminController 'search' => false, 'callback' => 'getProductImage', ), - 'hotel_name' => array( - 'title' => $this->l('Hotel'), + 'name' => array( + 'title' => $this->l('Room Type'), 'align' => 'center', 'orderby' => false, ), - 'name' => array( - 'title' => $this->l('Room Type'), + 'hotel_name' => array( + 'title' => $this->l('Hotel'), 'align' => 'center', 'orderby' => false, ), @@ -128,26 +128,18 @@ class AdminHotelRoomModuleSettingController extends ModuleAdminController $this->identifier = 'id_room_block'; parent::__construct(); - $this->hotelList = HotelBranchInformation::getProfileAccessedHotels( - $this->context->employee->id_profile, - 1 - ); - $objHotelRoomType = new HotelRoomType(); - if ($this->loadObject(true) - && $this->object->id - && ($roomInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct((int) $this->object->id_product)) - ) { - $hasHotelAccess = false; - foreach ($this->hotelList as $hotel) { - if ($hotel['id_hotel'] == $roomInfo['id_hotel']) { - $hasHotelAccess = true; + if ($this->hotelList = HotelBranchInformation::getProfileAccessedHotels($this->context->employee->id_profile, 1)) { + $objHotelRoomType = new HotelRoomType(); + if ($this->loadObject(true) + && $this->object->id + && ($roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct((int) $this->object->id_product)) + ) { + $idsHotel = array_column($this->hotelList, 'id_hotel'); + if (!in_array($roomTypeInfo['id_hotel'], $idsHotel)) { + $this->tabAccess['edit'] = 0; + $this->tabAccess['view'] = 0; } } - - if (!$hasHotelAccess) { - $this->tabAccess['edit'] = 0; - $this->tabAccess['view'] = 0; - } } } @@ -194,6 +186,9 @@ class AdminHotelRoomModuleSettingController extends ModuleAdminController { if (!($this->loadObject(true))) { return; + } else if (empty($this->hotelList)) { + $this->warnings[] = $this->l('No hotel found to create new hotel room block.'); + return; } $productName = false; @@ -216,9 +211,6 @@ class AdminHotelRoomModuleSettingController extends ModuleAdminController _PS_MODULE_DIR_.$this->module->name. '/views/templates/admin/hotel_room/product_search_block.tpl' ); - if (empty($this->hotelList)) { - $this->warnings[] = $this->l('You do not have access to any hotel to search for the room types.'); - } $this->fields_form = array( 'legend' => array( @@ -237,7 +229,7 @@ class AdminHotelRoomModuleSettingController extends ModuleAdminController 'id' => 'id_hotel', 'name' => 'hotel_name' ), - 'hint' => $this->l('Select the hotel.'), + 'hint' => $this->l('Select the hotel to search for the room types.'), ), array( 'label' => $this->l('Search Room Type'), @@ -441,7 +433,7 @@ class AdminHotelRoomModuleSettingController extends ModuleAdminController if (isset($pos[2]) && (int) $pos[2] === $idRoomBlock) { if ($objRoomBlock = new WkHotelRoomDisplay((int) $pos[2])) { if (isset($position) - && $objRoomBlock->updatePosition($way, $position, $idRoomBlock) + && $objRoomBlock->updatePosition($way, $position) ) { echo 'ok position '.(int) $position.' for hotel room block '.(int) $pos[1].'\r\n'; } else { diff --git a/modules/wkhotelroom/views/js/WkHotelRoomBlockAdmin.js b/modules/wkhotelroom/views/js/WkHotelRoomBlockAdmin.js index 6fed1a26d..50062660f 100644 --- a/modules/wkhotelroom/views/js/WkHotelRoomBlockAdmin.js +++ b/modules/wkhotelroom/views/js/WkHotelRoomBlockAdmin.js @@ -47,7 +47,7 @@ $(document).ready(function() { if (result) { var html = ''; $.each(result, function(key, value) { - html += '
  • ' + value.id+ '. '+ value.name + '
  • '; + html += '
  • '+value.name+' (#'+value.id+')
  • '; }); suggestion_ul.html(html).show(); } else { From 45ef9c3537449f68b8b109443d965e25efc35af4 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 21 May 2024 13:00:00 +0530 Subject: [PATCH 3/3] Fixed: Restrictions for the employees in case there is no hotel access available --- .../admin/AdminHotelRoomModuleSettingController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/wkhotelroom/controllers/admin/AdminHotelRoomModuleSettingController.php b/modules/wkhotelroom/controllers/admin/AdminHotelRoomModuleSettingController.php index f6242897d..4e37f08d8 100644 --- a/modules/wkhotelroom/controllers/admin/AdminHotelRoomModuleSettingController.php +++ b/modules/wkhotelroom/controllers/admin/AdminHotelRoomModuleSettingController.php @@ -140,6 +140,11 @@ class AdminHotelRoomModuleSettingController extends ModuleAdminController $this->tabAccess['view'] = 0; } } + } else { + if ($this->loadObject(true) && $this->object->id) { + $this->tabAccess['view'] =0; + $this->tabAccess['edit'] =0; + } } } @@ -186,7 +191,7 @@ class AdminHotelRoomModuleSettingController extends ModuleAdminController { if (!($this->loadObject(true))) { return; - } else if (empty($this->hotelList)) { + } else if (!$this->object->id && empty($this->hotelList)) { $this->warnings[] = $this->l('No hotel found to create new hotel room block.'); return; }