Prestashop无需分页即可显示所有产品类别

时间:2013-05-31 05:44:17

标签: categories prestashop

我正在为prestashop中的类别页面构建一个模块。

基本上在我的module.php中我有这段代码:

$category = new Category(Context::getContext()->shop->getCategory(),(int)Context::getContext()->language->id);
    $nb = (int)(Configuration::get('MOD_NBR'));
    $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10));

    $this->smarty->assign(array(
        'myproducts' => $products,
        'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
        'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
    ));

然后在mymodule.tpl中我有这个:

{foreach from=$products item=product name=myproducts}

+ other stuff

问题是我需要获取该类别中的所有产品,但它只在第一页上显示产品。我无法完全删除或修改分页,因为我需要分类页面上的其他产品进行分页,但在我的模块中我希望立即获取所有产品(之后我将过滤它们以仅显示其中一些)

你可能已经看到我有点失落,但也非常绝望,我会感激任何指导:)

感谢

1 个答案:

答案 0 :(得分:4)

在您的代码中,您有:

$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10));

对应于:

/**
  * Return current category products
  *
  * @param integer $id_lang Language ID
  * @param integer $p Page number
  * @param integer $n Number of products per page
  * @param boolean $get_total return the number of results instead of the results themself
  * @param boolean $active return only active products
  * @param boolean $random active a random filter for returned products
  * @param int $random_number_products number of products to return if random is activated
  * @param boolean $check_access set to false to return all products (even if customer hasn't access)
  * @return mixed Products or number of products
  */
public function getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null)

因此,您要求提供页面1$nb10元素。 尝试在该行$nb = 10000;之前添加以显示多达10k的产品(如果您的类别包含超过10k的产品,请随意增加产品)

所以它应该是这样的:

$category = new Category(Context::getContext()->shop->getCategory(),(int)Context::getContext()->language->id);
$nb = 10000;
$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10));

$this->smarty->assign(array(
    'myproducts' => $products,
    'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
    'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
));

更新:正在审核您的问题我发现您在模板中正在迭代$products变量,但将其指定为myproducts。我猜测smarty的指定变量$products仅包含第一页,$myproducts包含已获得的变量。

尝试将模板更新为:

{foreach from=$myproducts item=product name=myproducts}