From 0c8615b1996cec20fb528eabe2c9c65cdbb8026a Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 15 Sep 2023 16:43:39 +0530 Subject: [PATCH] Removed Filter by places and added advanced filters on Manager Room Types page at back office --- .../products/helpers/list/list_header.tpl | 399 +++++++++++++++++- classes/Product.php | 16 + classes/controller/AdminController.php | 9 +- classes/helper/HelperList.php | 5 + controllers/admin/AdminProductsController.php | 129 ++++-- 5 files changed, 513 insertions(+), 45 deletions(-) diff --git a/admin/themes/default/template/controllers/products/helpers/list/list_header.tpl b/admin/themes/default/template/controllers/products/helpers/list/list_header.tpl index 27872f854..6f2143969 100644 --- a/admin/themes/default/template/controllers/products/helpers/list/list_header.tpl +++ b/admin/themes/default/template/controllers/products/helpers/list/list_header.tpl @@ -25,12 +25,399 @@ {extends file="helpers/list/list_header.tpl"} -{block name=leadin} - {if isset($category_tree)} -
-
- {$category_tree} +{block name="tableFilter"}{/block} +{block name="override_form_extra"} + {if !$simple_header && $show_filters} + +
+
+
+
+ + +
+
+
+
+ +
+
+
+
+
+ {if $filters_has_value} +
+ {l s='Filters: '} + + {foreach $fields_display AS $key => $params} + {if (!isset($params.search) || $params.search) && $params.value != ''} + {if ($params.type == 'date' || $params.type == 'datetime') && $params.value|is_array} + {assign var="filter_value" value=''} + {foreach $params.value as $value} + {if ($value|is_string && !empty($value))} + {if empty($filter_value)} + {assign var="filter_value" value=$value} + {else} + {assign var="filter_value" value="`$filter_value` - `$value`"} + {/if} + {/if} + {/foreach} + {if !empty($filter_value)} + + {$params['title']|escape:'html':'UTF-8'}: {$filter_value|escape:'html':'UTF-8'} + + + {/if} + {elseif $params.type == 'range' && $params.value|is_array} + {assign var="filter_value" value=''} + {foreach $params.value as $value} + {if ($value|is_string && !empty($value))} + {if empty($filter_value)} + {assign var="filter_value" value=$value} + {else} + {assign var="filter_value" value="`$filter_value` - `$value`"} + {/if} + {/if} + {/foreach} + {if !empty($filter_value)} + + {$params['title']|escape:'html':'UTF-8'}: {$filter_value|escape:'html':'UTF-8'} + + + {/if} + {else if $params.type == 'select'} + + {$params['title']|escape:'html':'UTF-8'}: {$params['list'][$params['value']]|escape:'html':'UTF-8'} + + + {else if $params.type == 'select_multiple_and'} + + {$params['title']|escape:'html':'UTF-8'}: + + {foreach from=$params.value item=option name=foreachInfo} + {$params.list[$option]}{if !$smarty.foreach.foreachInfo.last}, {/if} + {/foreach} + + + + {else if $params.type == 'select_multiple_or'} + + {$params['title']|escape:'html':'UTF-8'}: + + {foreach from=$params.value item=option name=foreachInfo} + {$params.list[$option]}{if !$smarty.foreach.foreachInfo.last} | {/if} + {/foreach} + + + + {else} + + {$params['title']|escape:'html':'UTF-8'}: {$params['value']|escape:'html':'UTF-8'} + + + {/if} + {/if} + {/foreach} + +
+ {/if} +
+
+
+
+ {foreach $fields_display AS $key => $params} + {if !isset($params.search) || $params.search} +
+ +
+ {if $params.type == 'range'} +
+ + +
+ {else if $params.type == 'bool'} + + {elseif $params.type == 'date' || $params.type == 'datetime'} +
+
+ + + + + +
+
+ + + + + +
+ +
+ {elseif $params.type == 'select'} + {if isset($params.filter_key)} + + {/if} + {elseif $params.type == 'select_multiple_and'} + + {elseif $params.type == 'select_multiple_or'} + + {else} + + {/if} +
+
+ {/if} + {/foreach} + {if $has_actions || $show_filters} +
+
+ {if $show_filters} + + + {if $filters_has_value} + + {/if} + + {/if} +
+ {/if} +
+
+
+
+
+ + {/if} -{/block} +{/block} \ No newline at end of file diff --git a/classes/Product.php b/classes/Product.php index 84fc215a2..c88c77e00 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -1414,6 +1414,22 @@ class ProductCore extends ObjectModel return $result; } + public static function getAllServiceProducts($activeOnly = true, $idLang = null) + { + if (!$idLang) { + $idLang = Context::getContext()->language->id; + } + + $sql = 'SELECT p.*, pl.* + FROM `'._DB_PREFIX_.'product` p + LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON + (pl.`id_product` = p.`id_product` AND pl.`id_lang` = '.(int) $idLang.') + WHERE p.`booking_product` = 0'.($activeOnly ? ' AND p.`active` = 1' : '').' + ORDER BY p.`id_product`'; + + return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); + } + public function getAvailableServiceProductsCategories($id_lang, $front = false, $active = true, Context $context = null) { if (!$context) { diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index ea3a469f7..8f5e90583 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -875,7 +875,7 @@ class AdminControllerCore extends Controller if ($field = $this->filterToField($key, $filter)) { $type = (array_key_exists('filter_type', $field) ? $field['filter_type'] : (array_key_exists('type', $field) ? $field['type'] : false)); - if (($type == 'date' || $type == 'datetime' || $type == 'range') && is_string($value)) { + if ((in_array($type, array('date', 'datetime', 'range', 'select_multiple_and', 'select_multiple_or'))) && is_string($value)) { $value = json_decode($value, true); } $key = isset($tmp_tab[1]) ? $tmp_tab[0].'.`'.$tmp_tab[1].'`' : '`'.$tmp_tab[0].'`'; @@ -895,7 +895,12 @@ class AdminControllerCore extends Controller } /* Only for date filtering (from, to) */ if (is_array($value)) { - if ($type == 'range') { + if ($type == 'select_multiple_and') { + $sql_filter .= ' AND '.pSQL($key).' IN ('.pSQL(implode(',', $value)).')'; + $this->_filterHaving .= ' AND COUNT(DISTINCT '.pSQL($key).') = '.(int) count($value); + } elseif ($type == 'select_multiple_or') { + $sql_filter .= ' AND '.pSQL($key).' IN ('.pSQL(implode(',', $value)).')'; + } elseif ($type == 'range') { if (isset($value[0]) && !empty($value[0])) { if (!Validate::isUnsignedInt($value[0])) { $this->errors[] = Tools::displayError('The \'From\' value is invalid'); diff --git a/classes/helper/HelperList.php b/classes/helper/HelperList.php index e807008dc..c1f944ff3 100644 --- a/classes/helper/HelperList.php +++ b/classes/helper/HelperList.php @@ -681,6 +681,11 @@ class HelperListCore extends Helper } break; + case 'select_multiple_and': + case 'select_multiple_or': + $value = json_decode($value, true); + break; + case 'text': if (!Validate::isCleanHtml($value)) { $value = ''; diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 542c4bdb6..65ee35b56 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -194,12 +194,17 @@ class AdminProductsControllerCore extends AdminController LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_product` = a.`id_product` AND image_shop.`cover` = 1 AND image_shop.id_shop = '.$id_shop.') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_image` = image_shop.`id_image`) LEFT JOIN `'._DB_PREFIX_.'product_download` pd ON (pd.`id_product` = a.`id_product` AND pd.`active` = 1) - LEFT JOIN `'._DB_PREFIX_.'address` aa ON (aa.`id_hotel` = hb.`id`)'; + LEFT JOIN `'._DB_PREFIX_.'address` aa ON (aa.`id_hotel` = hb.`id`) + LEFT JOIN `'._DB_PREFIX_.'htl_advance_payment` hap ON (hap.`id_product` = a.`id_product`) + LEFT JOIN `'._DB_PREFIX_.'feature_product` fp ON (fp.`id_product` = a.`id_product`) + LEFT JOIN `'._DB_PREFIX_.'htl_room_type_demand` hrtd ON (hrtd.`id_product` = a.`id_product`) + LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product` hrtsp ON ((hrtsp.`element_type` = '.(int) RoomTypeServiceProduct::WK_ELEMENT_TYPE_HOTEL.' AND hrtsp.`id_element` = hrt.`id_hotel`) OR (hrtsp.`element_type` = '.(int) RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE.' AND hrtsp.`id_element` = a.`id_product`))'; $this->_select .= ' (SELECT COUNT(hri.`id`) FROM `'._DB_PREFIX_.'htl_room_information` hri WHERE hri.`id_product` = a.`id_product`) as num_rooms, '; - $this->_select .= 'hrt.`adults`, hrt.`children`, hb.`id` as id_hotel, aa.`city`, hbl.`hotel_name`, '; + $this->_select .= 'hrt.`adults`, hrt.`children`, hrt.`max_guests`, hb.`id` as id_hotel, aa.`city`, hbl.`hotel_name`, '; $this->_select .= 'shop.`name` AS `shopname`, a.`id_shop_default`, '; $this->_select .= $alias_image.'.`id_image` AS `id_image`, cl.`name` AS `name_category`, '.$alias.'.`price`, 0 AS `price_final`, a.`is_virtual`, pd.`nb_downloadable`, sav.`quantity` AS `sav_quantity`, '.$alias.'.`active`, IF(sav.`quantity`<=0, 1, 0) AS `badge_danger`'; + $this->_select .= ', hap.`active` AS advance_payment'; if ($join_category) { $this->_join .= ' INNER JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = a.`id_product` AND cp.`id_category` = '.(int)$this->_category->id.') '; @@ -210,7 +215,8 @@ class AdminProductsControllerCore extends AdminController $this->_where .= ' AND a.`booking_product` = 1'; $this->_use_found_rows = false; - $this->_group = ''; + $this->_group = ' GROUP BY a.`id_product`'; + $this->_orderBy = 'a.id_product'; $this->fields_list = array(); $this->fields_list['id_product'] = array( @@ -246,22 +252,25 @@ class AdminProductsControllerCore extends AdminController $this->fields_list['adults'] = array( 'title' => $this->l('Adults'), 'filter_key' => 'hrt!adults', + 'type' => 'range', 'align' => 'center', ); $this->fields_list['child'] = array( 'title' => $this->l('Children'), 'filter_key' => 'hrt!children', + 'type' => 'range', 'align' => 'center', ); // use it for total rooms $this->fields_list['num_rooms'] = array( 'title' => $this->l('Total Rooms'), 'align' => 'center', + 'type' => 'range', 'havingFilter' => true, ); $this->fields_list['price'] = array( - 'title' => $this->l('Base price'), - 'type' => 'price', + 'title' => $this->l('Base Price'), + 'type' => 'range', 'align' => 'text-left', 'filter_key' => 'a!price' ); @@ -279,11 +288,87 @@ class AdminProductsControllerCore extends AdminController 'active' => 'status', 'filter_key' => $alias.'!active', 'align' => 'text-center', - 'type' => 'bool', - 'class' => 'fixed-width-sm', + 'type' => 'select', + 'list' => array(1 => $this->l('Yes'), 0 => $this->l('No')), + 'optional' => true, + 'visible_default' => true, 'orderby' => false ); + $this->fields_list['max_guests'] = array( + 'title' => $this->l('Maximum Occupancy'), + 'filter_key' => 'hrt!max_guests', + 'type' => 'range', + 'align' => 'center', + 'optional' => true, + ); + + $this->fields_list['advance_payment'] = array( + 'title' => $this->l('Advance Payment'), + 'active' => 'advance_payment', + 'filter_key' => 'hap!active', + 'align' => 'text-center', + 'type' => 'select', + 'list' => array(1 => $this->l('Yes'), 0 => $this->l('No')), + 'optional' => true, + 'visible_default' => true, + 'orderby' => false + ); + + $taxRulesGroups = array(); + foreach (TaxRulesGroup::getTaxRulesGroups(true) as $taxRulesGroup) { + $taxRulesGroups[$taxRulesGroup['id_tax_rules_group']] = $taxRulesGroup['name']; + } + $this->fields_list['id_tax_rules_group'] = array( + 'title' => $this->l('Tax Rules'), + 'align' => 'text-center', + 'type' => 'select_multiple_or', + 'filter_key' => 'a!id_tax_rules_group', + 'list' => $taxRulesGroups, + 'displayed' => false, + ); + + $features = array(); + foreach (Feature::getFeatures($this->context->language->id) as $feature) { + $features[$feature['id_feature']] = $feature['name']; + } + $this->fields_list['id_feature'] = array( + 'title' => $this->l('Features'), + 'align' => 'text-center', + 'type' => 'select_multiple_and', + 'filter_key' => 'fp!id_feature', + 'list' => $features, + 'displayed' => false, + ); + + $serviceProducts = array(); + foreach (Product::getAllServiceProducts() as $serviceProduct) { + $serviceProducts[$serviceProduct['id_product']] = $serviceProduct['name']; + } + $this->fields_list['id_service_product'] = array( + 'title' => $this->l('Service Products'), + 'align' => 'text-center', + 'type' => 'select_multiple_and', + 'filter_key' => 'hrtsp!id_product', + 'list' => $serviceProducts, + 'displayed' => false, + ); + + $additionalFacilities = array(); + $objHotelRoomTypeGlobalDemand = new HotelRoomTypeGlobalDemand(); + $demands = $objHotelRoomTypeGlobalDemand->getAllDemands(); + foreach ($demands as $demand) { + $additionalFacilities[$demand['id_global_demand']] = $demand['name']; + } + $this->fields_list['id_global_demand'] = array( + 'title' => $this->l('Additional Facilities'), + 'align' => 'text-center', + 'type' => 'select_multiple_and', + 'filter_key' => 'hrtd!id_global_demand', + 'list' => $additionalFacilities, + 'displayed' => false, + ); + if ($join_category && (int)$this->id_current_category) { $this->fields_list['position'] = array( 'title' => $this->l('Position'), @@ -2264,36 +2349,6 @@ class AdminProductsControllerCore extends AdminController } $this->tpl_form_vars['product_tabs'] = $product_tabs; } - } else { - if ($id_category = (int)$this->id_current_category) { - self::$currentIndex .= '&id_category='.(int)$this->id_current_category; - } - - // If products from all categories are displayed, we don't want to use sorting by position - if (!$id_category) { - $this->_defaultOrderBy = $this->identifier; - if ($this->context->cookie->{$this->table.'Orderby'} == 'position') { - unset($this->context->cookie->{$this->table.'Orderby'}); - unset($this->context->cookie->{$this->table.'Orderway'}); - } - } - if (!$id_category) { - $id_category = Configuration::get('PS_ROOT_CATEGORY'); - } - $this->tpl_list_vars['is_category_filter'] = (bool)$this->id_current_category; - - // Generate category selection tree - $catFilter = $this->l('Filter by Places'); - $tree = new HelperTreeCategories('categories-tree', $catFilter); - $tree->setAttribute('is_category_filter', (bool)$this->id_current_category) - ->setAttribute('base_url', preg_replace('#&id_category=[0-9]*#', '', self::$currentIndex).'&token='.$this->token) - ->setInputName('id-category') - ->setRootCategory((int)Configuration::get('PS_LOCATIONS_CATEGORY')) - ->setSelectedCategories(array((int)$id_category)); - $this->tpl_list_vars['category_tree'] = $tree->render(); - - // used to build the new url when changing category - $this->tpl_list_vars['base_url'] = preg_replace('#&id_category=[0-9]*#', '', self::$currentIndex).'&token='.$this->token; } parent::initContent();