Make order status filter multi-select

This commit is contained in:
Abhishek Kumar
2023-09-25 17:47:43 +05:30
parent 13f759c8b1
commit 8064ca32f3
5 changed files with 42 additions and 6 deletions

View File

@@ -229,6 +229,7 @@ $chosen-sprite-path: '../img/chosen-sprite.png'
border: 0 !important
color: $gray
height: $chosen-multi-height - 8px
width: 100% !important
margin: 0
padding: 4px
outline: 0

View File

@@ -141,6 +141,16 @@
{$params['title']|escape:'html':'UTF-8'}: <span class="filter_value">{$params['list'][$params['value']]|escape:'html':'UTF-8'}</span>
<i class="icon-times"></i>
</span>
{else if $params.type == 'select_multiple_or'}
<span data-filter_key="{if isset($params.filter_key)}{$params.filter_key}{else}{$key}{/if}" data-filter_type="{$params.type}">
{$params['title']|escape:'html':'UTF-8'}:
<span class="filter_value">
{foreach from=$params.value item=option name=foreachInfo}
{$params.list[$option]}{if !$smarty.foreach.foreachInfo.last} | {/if}
{/foreach}
</span>
<i class="icon-times"></i>
</span>
{else}
<span data-filter_key="{if isset($params.filter_key)}{$params.filter_key}{else}{$key}{/if}" data-filter_type="{$params.type}">
{$params['title']|escape:'html':'UTF-8'}: <span class="filter_value">{$params['value']|escape:'html':'UTF-8'}</span>
@@ -255,6 +265,14 @@
{/if}
</select>
{/if}
{elseif $params.type == 'select_multiple_or'}
<select id="filter_input_{$key}" class="filter{if isset($params.align) && $params.align == 'center'}center{/if} select_multiple_or chosen" multiple name="{$list_id}Filter_{$params.filter_key}[]" {if isset($params.width)} style="width:{$params.width}px"{/if}>
{if isset($params.list) && is_array($params.list)}
{foreach $params.list AS $option_value => $option_display}
<option value="{$option_value}" {if isset($params.value) && $params.value}{if in_array($option_value, $params.value)} selected="selected"{/if}{/if}>{$option_display}</option>
{/foreach}
{/if}
</select>
{else}
<input type="text" id="filter_input_{$key}" class="filter" name="{$list_id}Filter_{if isset($params.filter_key)}{$params.filter_key}{else}{$key}{/if}" value="{$params.value|escape:'html':'UTF-8'}" {if isset($params.width) && $params.width != 'auto'} style="width:{$params.width}px"{/if} />
{/if}
@@ -296,11 +314,19 @@
$('#list_filters_panel').find('[name*="'+$(this).parent().data('filter_key')+'"]').val('');
} else if (type == 'range') {
$('#list_filters_panel').find('[name*="orderFilter_'+$(this).parent().data('filter_key')+'"]').val('');
} else if (type == 'select') {
$('#list_filters_panel').find('select[name="orderFilter_'+$(this).parent().data('filter_key')+'"] option:selected').prop("selected", false);
} else if (type == 'select' || type == 'select_multiple_or') {
$('#list_filters_panel').find('select[name*="orderFilter_'+$(this).parent().data('filter_key')+'"] option:selected').prop('selected', false);
} else {
$('#list_filters_panel').find('input[name="orderFilter_'+$(this).parent().data('filter_key')+'"]').val('');
}
// set post data for empty multi-select filters
$(form).find('select[multiple]').each(function (i, selectElement) {
if ($(selectElement).find('option:selected').length == 0) {
$(form).append('<input type="hidden" name="' + $(selectElement).attr('name').slice(0, -2) + '" value="">');
}
});
form.submit();
});
});

View File

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

View File

@@ -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 = '';

View File

@@ -246,11 +246,10 @@ class AdminOrdersControllerCore extends AdminController
),
'osname' => array(
'title' => $this->l('Status'),
'type' => 'select',
'type' => 'select_multiple_or',
'color' => 'color',
'list' => $this->statuses_array,
'filter_key' => 'os!id_order_state',
'filter_type' => 'int',
'order_key' => 'osname',
'optional' => true,
'visible_default' => true