Merge pull request #1025 from vishal-singh-webkul/gli-2015
Added: Hotel name and room type name in the list in the hotel room block module, added hotel search option while creating new room block.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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',
|
||||
),
|
||||
'name' => array(
|
||||
'title' => $this->l('Room Type'),
|
||||
'align' => 'center',
|
||||
'orderby' => false,
|
||||
),
|
||||
'hotel_name' => array(
|
||||
'title' => $this->l('Hotel'),
|
||||
'align' => 'center',
|
||||
'orderby' => false,
|
||||
),
|
||||
'active' => array(
|
||||
'title' => $this->l('Active'),
|
||||
'align' => 'center',
|
||||
@@ -109,6 +128,24 @@ class AdminHotelRoomModuleSettingController extends ModuleAdminController
|
||||
$this->identifier = 'id_room_block';
|
||||
|
||||
parent::__construct();
|
||||
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;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($this->loadObject(true) && $this->object->id) {
|
||||
$this->tabAccess['view'] =0;
|
||||
$this->tabAccess['edit'] =0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getProductImage($idProduct)
|
||||
@@ -152,23 +189,27 @@ class AdminHotelRoomModuleSettingController extends ModuleAdminController
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
if (!($obj = $this->loadObject(true))) {
|
||||
if (!($this->loadObject(true))) {
|
||||
return;
|
||||
} else if (!$this->object->id && empty($this->hotelList)) {
|
||||
$this->warnings[] = $this->l('No hotel found to create new hotel room block.');
|
||||
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(
|
||||
@@ -182,6 +223,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 to search for the room types.'),
|
||||
),
|
||||
array(
|
||||
'label' => $this->l('Search Room Type'),
|
||||
'type' => 'html',
|
||||
@@ -384,7 +438,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 {
|
||||
|
||||
@@ -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.name+' (#'+value.id+')</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('');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user