1

我正在为 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

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

如您所见,我有点迷茫,但也很绝望,我将不胜感激任何指导:)

谢谢

4

1 回答 1

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}
于 2013-06-03T16:37:01.663 回答