magento中自定义集合的分页问题

发布于 2024-12-02 22:30:45 字数 839 浏览 0 评论 0原文

我创建了自定义块来从多个类别中检索产品。我已将此块扩展到核心产品列表块。分页器不适用于自定义集合,知道为什么分页不起作用吗? 我在 collection.php 中使用这个函数

public function addCategoriesFilter($categories)
    {

    $alias = 'cat_index';
    $categoryCondition = $this->getConnection()->quoteInto(
    $alias.'.product_id=e.entity_id AND '.$alias.'.store_id=? AND ',
    $this->getStoreId()
    );

    $categoryCondition.= $alias.'.category_id IN ('.$categories.')';
    $this->getSelect()->group('e.entity_id');
    $this->getSelect()->joinInner(
    array($alias => $this->getTable('catalog/category_product_index')),
    $categoryCondition,
    array('position'=>'position')
    );

    $this->_categoryIndexJoined = true;
    $this->_joinFields['position'] = array('table'=>$alias, 'field'=>'position' );

    return $this;

}

I have created custom block to retrieve product from multiple categories. I have extended this block to core product List block. Pager is not working on custom collection, have any idea why paging is not working?
I am using this function in collection.php

public function addCategoriesFilter($categories)
    {

    $alias = 'cat_index';
    $categoryCondition = $this->getConnection()->quoteInto(
    $alias.'.product_id=e.entity_id AND '.$alias.'.store_id=? AND ',
    $this->getStoreId()
    );

    $categoryCondition.= $alias.'.category_id IN ('.$categories.')';
    $this->getSelect()->group('e.entity_id');
    $this->getSelect()->joinInner(
    array($alias => $this->getTable('catalog/category_product_index')),
    $categoryCondition,
    array('position'=>'position')
    );

    $this->_categoryIndexJoined = true;
    $this->_joinFields['position'] = array('table'=>$alias, 'field'=>'position' );

    return $this;

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没有你我更好 2024-12-09 22:30:45

经过几个小时的探索并阅读了几乎所有有关自定义集合分页的论坛后,我找到了一种显示自定义集合页面分页的方法。

我需要显示我的页面的工具栏,该工具栏将显示糖尿病值为“是”的产品(糖尿病是自定义属性)。

首先我们需要过滤 phtml 文件上的集合:

$_productCollection = Mage::getModel('catalog/product')->setStoreId($storeId)getCollection()->addAttributeToFilter("diabetic",1);

/* populate toolbar collection with your collection */
$toolbar = Mage::getBlockSingleton('catalog/product_list')->getToolbarBlock();
$toolbar->setCollection($_productCollection);
echo $toolbar->toHtml();

After exploring many hours and reading almost all forums for paging on custom collection I have found a way to show paging for custom collection page.

I have a requirement to show toolbar for my page that will show products which are having diabetic value as yes (diabetic is the custom attribute).

Firstly we need to filter the collection on phtml file:

$_productCollection = Mage::getModel('catalog/product')->setStoreId($storeId)getCollection()->addAttributeToFilter("diabetic",1);

/* populate toolbar collection with your collection */
$toolbar = Mage::getBlockSingleton('catalog/product_list')->getToolbarBlock();
$toolbar->setCollection($_productCollection);
echo $toolbar->toHtml();
夏末 2024-12-09 22:30:45

<

block type="page/html_pager" name="product_list_toolbar_pager" />

这需要添加到您尝试加载产品的 xml 块中,以便它获取工具栏和分页器。

请参阅此链接作为参考。
带分页的产品

<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">

<block type="page/html_pager" name="product_list_toolbar_pager" />

This needs to be added to the xml block where you are attempting to load product so that it gets the toolbar and the pager.

See this link as reference.
Products with Pagination

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文