Jump to content

Pagination on HelperList


sukamto

Recommended Posts

Hi there, i am new to prestashop and having problem with pagination in helperlist while developing admin module for prestashop 1.6.1.4.

what i want to achieve is to display all transaction in a list with pagination. However, the list returns all transaction data and the pagination link isn't working. I do not know where could possibly be wrong with my code and hope someone could help me.

 

Admin Controller File

class AdminCustomerWalletController extends ModuleAdminController
{
 
     public function walletTransactionList($id_wallet)
     {
          $this->fields_list = array(
                 'process_date' => array(
                 'title' => $this->l('Process Date'),
                 'type' => 'datetime'
            ),
          'credit' => array(
                'title' => $this->l('Credit'),
               'type' => 'price',
                'align' => 'text-right',
                'class' => 'fixed-width-xs'
            ),
          'debit' => array(
                'title' => $this->l('Debit'),
               'type' => 'price',
                'align' => 'text-right',
                'class' => 'fixed-width-xs'
            ),
          'saldo' => array(
                'title' => $this->l('Saldo'),
               'type' => 'price',
                'align' => 'text-right',
                'class' => 'fixed-width-xs'
            ),
        );
 
 
          $list = WalletTransaction::getWalletTransaction($id_wallet);
          $helper = new HelperList();
          $helper->shopLinkType = $this->shopLinkType;;
          $helper->show_toolbar = true;
          $helper->title = 'Customer Wallet Transactions';
          $helper->listTotal = count($list);
          $helper->_default_pagination = 20;
 
          return $helper->generateList($list, $this->fields_list);
     }
 
}
 
Object Model Class
class WalletTransaction extends ObjectModel
{
 
     public static function getWalletTransaction($id_wallet = null)
     {
          if (($id_wallet || !empty($id_wallet)) && is_numeric($id_wallet))
          {
              $sql1 = 'set @saldo := 0';
              $sql2 = 'SELECT * FROM 
                            (SELECT `id_wallet`,`process_date`,
                            IF (`tran_type` = \'DTU\', ifnull(`tran_amount`,0) * -1, 0) credit,
                            IF (`tran_type` = \'DWD\', ifnull(`tran_amount`,0) * 1, 0) debit,
                            (@saldo := if (`tran_type` = \'DTU\', @saldo + (ifnull(`tran_amount`,0) * -1), @saldo -   ifnull(`tran_amount`,0))) saldo
                            FROM `'._DB_PREFIX_.'wallet_transaction`
                            WHERE `id_wallet` = ' . (int)$id_wallet . ' AND `tran_type` in (\'DTU\',\'DWD\')
                            ) wallet_transaction
                            ORDER BY `process_date` ASC';
 
              Db::getInstance(_PS_USE_SQL_SLAVE_)->query($sql1);
              return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql2);
           }
 
           return false;
     }
}

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...