Question

I have developed a Prestashop online store with a custom template.

Now, everything is OK, but the category product listing. I'm showing rows of three products, so, when showing the default pagination of 10 products per page, last row has only 1 product.

I cannot find how to change the pagination options so the user cannot choose the default values of 10,20 and 30 products per page and change them for 12,24,36

Thankyou in advance-

Was it helpful?

Solution

I found the solution (Prestashop 1.5.3.1).

Simply needed to edit FrontController.php. But, to make it cleaner I copied the pagination method to my overrided FrontController and changed only the line starting by $nArray = (int) Configuration::get('PS_PRODUCTS_PER_PAGE'):

<?php
class FrontController extends FrontControllerCore
{
  public function pagination($nbProducts = 13)
  {
    if (!self::$initialized)
      $this->init();
    elseif (!$this->context)
      $this->context = Context::getContext();

    $nArray = (int) Configuration::get('PS_PRODUCTS_PER_PAGE') != 12 ? 
               array((int) Configuration::get('PS_PRODUCTS_PER_PAGE'), 12, 24, 50) : 
               array(12, 24, 50);
    // Clean duplicate values
    $nArray = array_unique($nArray);
    asort($nArray);
    $this->n = abs((int) (Tools::getValue('n', ((isset($this->context->cookie->nb_item_per_page) && $this->context->cookie->nb_item_per_page >= 10) ? $this->context->cookie->nb_item_per_page : (int) Configuration::get('PS_PRODUCTS_PER_PAGE')))));
    $this->p = abs((int) Tools::getValue('p', 1));

    if (!is_numeric(Tools::getValue('p', 1)) || Tools::getValue('p', 1) < 0)
      Tools::redirect(self::$link->getPaginationLink(false, false, $this->n, false, 1, false));

    $current_url = tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']);
    //delete parameter page
    $current_url = preg_replace('/(\?)?(&amp;)?p=\d+/', '$1', $current_url);

    $range = 2; /* how many pages around page selected */

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

    if (isset($this->context->cookie->nb_item_per_page) && $this->n != $this->context->cookie->nb_item_per_page && in_array($this->n, $nArray))
      $this->context->cookie->nb_item_per_page = $this->n;

    $pages_nb = ceil($nbProducts / (int) $this->n);
    if ($this->p > $pages_nb && $nbProducts <> 0)
      Tools::redirect(self::$link->getPaginationLink(false, false, $this->n, false, $pages_nb, false));

    $start = (int) ($this->p - $range);
    if ($start < 1)
      $start = 1;
    $stop = (int) ($this->p + $range);
    if ($stop > $pages_nb)
      $stop = (int) $pages_nb;
    $this->context->smarty->assign('nb_products', $nbProducts);
    $pagination_infos = array(
        'products_per_page' => (int) Configuration::get('PS_PRODUCTS_PER_PAGE'),
        'pages_nb' => $pages_nb,
        'p' => $this->p,
        'n' => $this->n,
        'nArray' => $nArray,
        'range' => $range,
        'start' => $start,
        'stop' => $stop,
        'current_url' => $current_url
    );
    $this->context->smarty->assign($pagination_infos);
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top