Jump to content

Re-coding options found in 'items per page' of the pagination in category


brandonc503

Recommended Posts

Change line 3 of pagination.php from:

$nArray = intval(Configuration::get('PS_PRODUCTS_PER_PAGE')) != 10 ? array(intval(Configuration::get('PS_PRODUCTS_PER_PAGE')), 10, 20, 50) : array(10, 20, 50);



to:

$nArray = intval(Configuration::get('PS_PRODUCTS_PER_PAGE')) != 12 ? array(intval(Configuration::get('PS_PRODUCTS_PER_PAGE')), 12, 24, 48) : array(12, 24, 48);



You'll need to go to Preferences > Products and change the "Products per page" from 10 to 12 to prevent the pagination options becoming "10, 12, 24, 48".

Link to comment
Share on other sites

  • 8 months later...

It seems to be moved in 1.4. Has anybody figured out where it is in 1.4?

Also, how to make the pagination disappear if there is certain amount or less products in the category? There is really no point to have it then, is there?

Link to comment
Share on other sites

It's on line 522 of classes/FrontController.php (in PrestaShop v1.4.1):

$nArray = (int)(Configuration::get('PS_PRODUCTS_PER_PAGE')) != 10 ? array((int)(Configuration::get('PS_PRODUCTS_PER_PAGE')), 10, 20, 50) : array(10, 20, 50);



You should create override/classes/FrontController.php, copy the pagination function, then to change it:

class FrontController extends FrontControllerCore
{
   public function pagination($nbProducts = 10)
   {
       if (!self::$initialized)
           $this->init();

       $nArray = (int)(Configuration::get('PS_PRODUCTS_PER_PAGE')) != 10 ? array((int)(Configuration::get('PS_PRODUCTS_PER_PAGE')), 10, 20, 50) : array(10, 20, 50);
       asort($nArray);
       $this->n = abs((int)(Tools::getValue('n', ((isset(self::$cookie->nb_item_per_page) AND self::$cookie->nb_item_per_page >= 10) ? self::$cookie->nb_item_per_page : (int)(Configuration::get('PS_PRODUCTS_PER_PAGE'))))));
       $this->p = abs((int)(Tools::getValue('p', 1)));
       $range = 2; /* how many pages around page selected */

       if ($this->p < 0)
           $this->p = 0;

       if (isset(self::$cookie->nb_item_per_page) AND $this->n != self::$cookie->nb_item_per_page AND in_array($this->n, $nArray))
           self::$cookie->nb_item_per_page = $this->n;

       if ($this->p > ($nbProducts / $this->n))
           $this->p = ceil($nbProducts / $this->n);
       $pages_nb = ceil($nbProducts / (int)($this->n));

       $start = (int)($this->p - $range);
       if ($start < 1)
           $start = 1;
       $stop = (int)($this->p + $range);
       if ($stop > $pages_nb)
           $stop = (int)($pages_nb);
       self::$smarty->assign('nb_products', $nbProducts);
       $pagination_infos = array(
           'pages_nb' => (int)($pages_nb),
           'p' => (int)($this->p),
           'n' => (int)($this->n),
           'nArray' => $nArray,
           'range' => (int)($range),
           'start' => (int)($start),
           'stop' => (int)($stop)
       );
       self::$smarty->assign($pagination_infos);
   }
}



PrestaShop already hides the pagination options that are less than the number of products, so I don't understand why you need to change it.

Link to comment
Share on other sites

Thank you!

PrestaShop already hides the pagination options that are less than the number of products, so I don’t understand why you need to change it.



Indeed it does hide the 'go to page 1, 2, 3 ...' options but not the dropdown 'display 10, 20, 50 per page'. I am in a category consisting 14 items and there are options to display 10 or 20. With only 14 products, this is really unnecessary so I'd better remove it.

Link to comment
Share on other sites

Oh, I see now why that is. This is because of the default 10 items. I did change it to 30, 60, 120 per page. There are 3 instances of '10' in the code, after changing them all to 30 it still displays the dropdown with an option '30' + customized 'all'.

Where did I go wrong here:

    public function pagination($nbProducts = 30)
   {
       if (!self::$initialized)
           $this->init();

       $nArray = (int)(Configuration::get('PS_PRODUCTS_PER_PAGE')) != 30 ? array((int)(Configuration::get('PS_PRODUCTS_PER_PAGE')), 30, 60, 120) : array(30, 30, 120);
       asort($nArray);
       $this->n = abs((int)(Tools::getValue('n', ((isset(self::$cookie->nb_item_per_page) AND self::$cookie->nb_item_per_page >= 30) ? self::$cookie->nb_item_per_page : (int)(Configuration::get('PS_PRODUCTS_PER_PAGE'))))));



EDIT: it was {if $nb_products > 10} in pagination.tpl.

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...