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

This commit is contained in:
vishalsingh.qlo325
2024-05-08 15:44:45 +05:30
parent 8dcfc9e892
commit e457cafbc9
3 changed files with 122 additions and 39 deletions

View File

@@ -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);

View File

@@ -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',

View File

@@ -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 += '<li class="suggestion_li"><a class="suggestion_a text-capitalize" data-primary="' + value.id + '" data-secondary="' + value.name + '">' + value.name + '</a></li>';
});
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 += '<li class="suggestion_li"><a class="suggestion_a text-capitalize" data-primary="' + value.id + '" data-secondary="' + value.name + '">' + value.id+ '. '+ value.name + '</a></li>';
});
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('');
});
});