Emilio1993 Posted March 25, 2020 Share Posted March 25, 2020 Salve. Utilizzo la versione di Prestashop 1.7.6.3 Nella scheda " Ordini " tra i vari filtri ( id,cliente,stato etcc ) vorrei aggiungere un filtro che mi consenta di filtrare gli ordini in base ad un range di ID Esempio da ordine 620800 a 621800. Riuscite a darmi un aiuto? Link to comment Share on other sites More sharing options...
EvaF Posted March 26, 2020 Share Posted March 26, 2020 there is possible to make it more elegant ( as Products list) but it means more changes. This solution is more general, but need at least the minimal knowledge of sql 1)at first make backup of files: a) /themes/default/template/helpers/list/list_header.tpl b) /controller/AdminController.php 2) change the /themes/default/template/helpers/list/list_header.tpl file this way: {* ------------- line 371 ----------------- *} {elseif $params.type == 'select'} {if isset($params.filter_key)} <select class="filter{if isset($params.align) && $params.align == 'center'}center{/if}" onchange="$('#submitFilterButton{$list_id}').focus();$('#submitFilterButton{$list_id}').click();" name="{$list_id}Filter_{$params.filter_key}" {if isset($params.width)} style="width:{$params.width}px"{/if}> <option value="" {if $params.value == ''} selected="selected" {/if}>-</option> {if isset($params.list) && is_array($params.list)} {foreach $params.list AS $option_value => $option_display} <option value="{$option_value}" {if (string)$option_display === (string)$params.value || (string)$option_value === (string)$params.value} selected="selected"{/if}>{$option_display}</option> {/foreach} {/if} </select> {/if} {else} {* ------------- added own filter ----------------- *} {if isset($params.whereFilter)&&$params.whereFilter} <div class="row"> <div class="input-group fixed-width-md center"> {/if} {* ------------- origin line ----------------- *} <input type="text" 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} /> {* ------------- origin line ----------------- *} {if isset($params.whereFilter)&&$params.whereFilter} </div> <div class="input-group fixed-width-md center"> <input type="text" class="filter" name="{$list_id}Filter_whereFilter" value="{if (string)$params.whereFilter === '1'}{else}{$params.whereFilter|escape:'html':'UTF-8'}{/if}" {if isset($params.width) && $params.width != 'auto'} style="width:{$params.width}px"{/if} /> </div> {/if} {* ------------- end of own filter ----------------- *} {/if} 3) change the /controller/AdminController.php this way: a) add new function: private function setWhereFilterValue($value) { foreach ($this->fields_list as $k => $v) { if ($v['whereFilter']) { $this->fields_list[$k]['whereFilter'] = $value; break; } } } b) modify processFilter() function public function processFilter() { ... ... foreach ($filters as $key => $value) { /* Extracting filters from $_POST on key filter_ */ if ($value != null && !strncmp($key, $prefix . $this->list_id . 'Filter_', 7 + Tools::strlen($prefix . $this->list_id))) { $key = Tools::substr($key, 7 + Tools::strlen($prefix . $this->list_id)); /* Table alias could be specified using a ! eg. alias!field */ $tmp_tab = explode('!', $key); $filter = count($tmp_tab) > 1 ? $tmp_tab[1] : $tmp_tab[0]; if ($field = $this->filterToField($key, $filter)) { ... ... } /* added own filter , that includes sql comentary to be able to remove it if "whereFilter" contains SQL error */ else{ if ($key=='whereFilter') { $sql_filter .= '/* custom whereFilter */ AND (' . $value . ') /* whereFilter end*/'; $this->setWhereFilterValue($value); } } /* end own filter */ } } } c) modify getList(..) function public function getList( $id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false ) { ... ... ... $this->_list = Db::getInstance()->executeS($this->_listsql, true, false); /* Backdoor - if whereFilter is present and SQL query contains error, remove whereFilter from query */ if ($this->_list === false) { if (strpos($whereClause, '/* custom whereFilter */') !== false) { $this->_list_error = Db::getInstance()->getMsgError(); $this->setWhereFilterValue('1'); $pattern = '/\/\* custom whereFilter (.)* whereFilter end\*\//i'; $this->_listsql = preg_replace($pattern, '', $this->_listsql); $list_count = preg_replace($pattern, '', $list_count); $this->_list = Db::getInstance()->executeS($this->_listsql, true, false); } } /* end of backdoor */ if ($this->_list === false) { $this->_list_error = Db::getInstance()->getMsgError(); break; } ... ... } 4) set own filter (f.e. into order list) - i.e. /controllers/admin/AdminOrdersController.php this way: public function __construct() { ... ... $this->fields_list = array( 'id_order' => array( 'title' => $this->trans('ID', array(), 'Admin.Global'), 'align' => 'text-center', /* added own filter */ 'whereFilter' => '1', /* added own filter */ 'class' => 'fixed-width-xs', ), ... ... } Result looks like: example of own filter: (id_order<=300) (id_order>500) AND (id_order<1000) but you can also filter other fields (total_paid_tax_incl >40000) (total_paid_tax_incl >400) and (total_paid_tax_incl<1000) the rule for correct name of fields is simple: (inspect element field you want to filter) if the name of input contains exclamation you will replace it with dot ( c.company like '%IBM%') OR ( c.company like '%AMD%') Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now