Search code examples
phpprestashoppaymentprestashop-1.6

PrestaShop 1.6 Back Office pagination not working correctly


Hello I'm developing PrestaShop paymnet module. I wish list all transaction and made that with Helper List class, I set paggination option, but paggination don't work correctly. At the bottom shows paggionation like 1..2..4 pages, but list all transaction. This is part of code from render helper list method.

$helper = new HelperList();

$helper->show_toolbar = false;
$helper->no_link = true; 
$helper->_pagination = array(10, 20, 50, 100, 200);

$content = $this->getCancelRows();
$helper->listTotal = count($this->getCancelRows());

return $helper->generateList($content, $this->fields_list);

Thank for all helping! I'sorry if I ask dublicate question, but my research end with unsuccess. Cheers!


Solution

  • I found a solution for this problem. Just must be added functionality for paginate the result. If somebody has similar problem. Below I paste working code.

    public function initList() {
    
        $content = $this->getCancelRows();
        $helper->listTotal = count( $this->getCancelRows() );
    
        /* Paginate the result */
        $page = ( $page = Tools::getValue( 'submitFilter' . $helper->table ) ) ? $page : 1;
        $pagination = ( $pagination = Tools::getValue( $helper->table . '_pagination' ) ) ? $pagination : 10;
        $content = $this->paginate_content( $content, $page, $pagination );
    
        return $helper->generateList( $content, $this->fields_list );
    
    }
    
    public function paginate_content( $content, $page = 1, $pagination = 10 ) {
    
       if( count($content) > $pagination ) {
            $content = array_slice( $content, $pagination * ($page - 1), $pagination );
       }
    
       return $content;
    
    }