Jump to content

Custom display number of products not working - pagination


Recommended Posts

Hi, i m trying to set custom values for display number of products in pagination.

 

Since i have three column layout, i want the options to be 12,24,48 instead of 10,20,50.

I changed FrontControler class in override folder like this:

public function pagination($nbProducts = 12)
{
	if (!self::$initialized)
		$this->init();
	$nArray = (int)(Configuration::get('PS_PRODUCTS_PER_PAGE')) != 12 ? array((int)
(Configuration::get('PS_PRODUCTS_PER_PAGE')), 12, 24, 48) : array(12, 24, 48);
	asort($nArray);
	$this->n = abs((int)(Tools::getValue('n', ((isset(self::$cookie->nb_item_per_page) AND
self::$cookie->nb_item_per_page >= 12) ? 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);
}

 

and changed the number of displayed product per page to 12 in product settings.

 

Its working if i m on first page in category, but when i enter the second page, etc. through pagination, the dropdown options change to 12,10,20,50. What am I doing wrong ?

 

Thanks in advance

Link to comment
Share on other sites

So now i know where is the problem, it seems that it has to do something with layered navigation module. I am using PrestaShop™ 1.4.6.2. Is there any update for Layered navigation module ? Since its not first problem caused by this module. I really need this module activated. But this problem is so far the worst. Really dont know what to do. Please help.

Link to comment
Share on other sites

  • 1 year later...

i think you need to find where is formed the LINK its salf which is used in pagination.

 

Like this section form ps 1.5

 

$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('/(\?)?(&)?p=\d+/', '$1', $current_url);
 $range = 2; /* how many pages around page selected */
....

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