我开发了一个带有自定义模板的Prestashop在线商店。
现在,一切正常,但类别产品列表。我正在显示三个产品的行,因此,当显示每页10个产品的默认分页时,最后一行只有一个产品。
我找不到如何更改分页选项,因此用户无法选择每页10,20和30个产品的默认值,并将其更改为12,24,36
提前谢谢 -
答案 0 :(得分:0)
我找到了解决方案(Prestashop 1.5.3.1)。
只需编辑FrontController.php
即可。但是,为了使其更清晰,我将pagination
方法复制到我的覆盖FrontController
并仅更改 从$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('/(\?)?(&)?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);
}
}