如何在prestashop中的renderList中插入预设的滤镜?

问题描述 投票:0回答:4

由于我能够在@TheDrot的帮助下选择上一个问题,现在当我重新初始化过滤时又出现了另一个问题,它不会使用标准过滤器返回,我需要一些帮助来知道我必须在代码让它工作。 result in image 我发送代码和结果图像但没有成功。 感谢您的帮助。 谢谢。 result 2

public function processResetFilters($list_id = null)    
    {
        if ($list_id === null) {
            $list_id = isset($this->list_id) ? $this->list_id : $this->table;
        }

        $prefix = '';//var_dump($list_id, $prefix, $this->context->cookie);
        $filters = $this->context->cookie->getFamily($prefix.$list_id.'Filter_');
        foreach ($filters as $cookie_key => $filter) {
            if (strncmp($cookie_key, $prefix.$list_id.'Filter_', 7 + Tools::strlen($prefix.$list_id)) == 0) {
                $key = substr($cookie_key, 7 + Tools::strlen($prefix.$list_id));
                if (is_array($this->fields_list) && array_key_exists($key, $this->fields_list)) {
                    $this->context->cookie->$cookie_key = null;
                }
                unset($this->context->cookie->$cookie_key);
            }
        }

        if (isset($this->context->cookie->{'submitFilter'.$list_id})) {
            unset($this->context->cookie->{'submitFilter'.$list_id});
        }
        if (isset($this->context->cookie->{$prefix.$list_id.'Orderby'})) {
            unset($this->context->cookie->{$prefix.$list_id.'Orderby'});
        }
        if (isset($this->context->cookie->{$prefix.$list_id.'Orderway'})) {
            unset($this->context->cookie->{$prefix.$list_id.'Orderway'});
        }

        $_POST = array();
        $this->_filter = false;
        unset($this->_filterHaving);
        unset($this->_having);

        //your code
       $table= 'contabilidade_faturacao';
    $startTime = date('Y-m-d', mktime(0, 0, 0, date('m')-1  , 1 , date('Y'))); 
    $endTime = date('Y-m-d', mktime(23, 59, 59, date('m'), date('d')-date('j'), date('Y'))); 
    $table = 'contabilidade_faturacao';
    $date_filter_key = $table.'Filter_cf!data';
    $this->context->cookie->{$date_filter_key} = serialize(array(
        $startTime,
        $endTime
    ));
    $this->context->cookie->write();
    }
php filter prestashop action-filter
4个回答
0
投票

这可以通过覆盖HelperList.php核心文件来实现(路径:/classes/helper/HelperList.php)

有一个名为 displayListHeader() 的函数,它获取列表中的所有过滤器并将它们传递到 TPL 文件(/admin/themes/default/template/helpers/list/list_header.tpl),该文件渲染所有过滤器。

您可以重写 HelperList.php 类中的 displayListHeader() 函数来更改 HelperList 中过滤器的行为。


0
投票
I apologize @TheDrot, but nothing is happening, I send my code to vers and can tell me where I am missing.
I send the image of my result.[result code in image][1]
I'm sorry I'm not figuring out how I can make it work but I'm still new to prestashop.
Thank you for your precious help.

public function processResetFilters($list_id = null)    
    {
        if ($list_id === null) {
            $list_id = isset($this->list_id) ? $this->list_id : $this->table;
        }

        $prefix = '';//var_dump($list_id, $prefix, $this->context->cookie);
        $filters = $this->context->cookie->getFamily($prefix.$list_id.'Filter_');
        foreach ($filters as $cookie_key => $filter) {
            if (strncmp($cookie_key, $prefix.$list_id.'Filter_', 7 + Tools::strlen($prefix.$list_id)) == 0) {
                $key = substr($cookie_key, 7 + Tools::strlen($prefix.$list_id));
                if (is_array($this->fields_list) && array_key_exists($key, $this->fields_list)) {
                    $this->context->cookie->$cookie_key = null;
                }
                unset($this->context->cookie->$cookie_key);
            }
        }

        if (isset($this->context->cookie->{'submitFilter'.$list_id})) {
            unset($this->context->cookie->{'submitFilter'.$list_id});
        }
        if (isset($this->context->cookie->{$prefix.$list_id.'Orderby'})) {
            unset($this->context->cookie->{$prefix.$list_id.'Orderby'});
        }
        if (isset($this->context->cookie->{$prefix.$list_id.'Orderway'})) {
            unset($this->context->cookie->{$prefix.$list_id.'Orderway'});
        }

        $_POST = array();
        $this->_filter = false;
        unset($this->_filterHaving);
        unset($this->_having);

        //your code
        $startTime = date('Y-m-d', mktime(0, 0, 0, date('m')-1  , 1 , date('Y'))); 
        $endTime = date('Y-m-d', mktime(23, 59, 59, date('m'), date('d')-date('j'), date('Y'))); 
        $table = 'contabilidade_faturacao';
        $date_filter_key = $this->table.'Filter_cf!data';
        if (!Tools::getIsset('local_'.$date_filter_key) && !isset($this->context->cookie->{$date_filter_key})) {
            $this->context->cookie->{$date_filter_key} = serialize(array(
                $startTime,
                $endTime
            ));
            $this->context->cookie->write();
        }
    }


  [1]: https://i.stack.imgur.com/2peoP.png

0
投票

在渲染列表之前,检查是否未设置日期过滤器,然后将默认日期过滤器写入 cookie。

$date_filter_key = $table.'Filter_cf!data';
if (!Tools::getIsset('local_'.$date_filter_key) && !isset($this->context->cookie->{$date_filter_key}) {
    $this->context->cookie->{$date_filter_key} = serialize(array(
        '2017-02-01',
        '2017-02-28'
    ));
    $this->context->cookie->write();
}

当您重置过滤器时,您必须使用默认过滤器重写 cookie。

public function processResetFilters($list_id = null)
{
    ...
    // your code
    $startTime = date('Y-m-d', mktime(0, 0, 0, date('m')-1  , 1 , date('Y'))); 
    $endTime = date('Y-m-d', mktime(23, 59, 59, date('m'), date('d')-date('j'), date('Y'))); 
    $table = 'contabilidade_faturacao';
    $date_filter_key = $this->table.'Filter_cf!data';
    $this->context->cookie->{$date_filter_key} = serialize(array(
        $startTime,
        $endTime
    ));
    $this->context->cookie->write();
}

0
投票

我通过这种方式达到了默认过滤:

$date_filter_key = $table . 'Filter_cf!date_add';
if (!Tools::getIsset('local_' . $date_filter_key) && !isset($this->context->cookie->{$date_filter_key})) {
    $_GET[$date_filter_key] = array('2024-01-01', '2024-01-31');
}
© www.soinside.com 2019 - 2024. All rights reserved.