Note that there are some explanatory texts on larger screens.

plurals
  1. POMagento Pagination bar Limiting the number of items
    primarykey
    data
    text
    <p>In magento ,I need to load <strong>only</strong> <strong>top 20 items</strong> from product collections with pagination bar(pagination bar should only have 4 pages because its only have 20 items - But in my case its having total product collection because magento pagination bar is taking whole collection object for creating toolbar without limit property).</p> <p>I have the following code</p> <pre><code> $_productCollection = Mage::getResourceModel('reports/product_collection') -&gt;addAttributeToSelect('*') -&gt;addOrderedQty() -&gt;setPageSize($limit) -&gt;setPage($p, $limit) -&gt;setOrder('ordered_qty', 'desc'); </code></pre> <p>And this returned 20 items correctly. When i set this to pagination bar by following method.</p> <pre><code>$magento_block = Mage::getSingleton('core/layout'); $productsHtml = $magento_block-&gt;createBlock('catalog/product_list'); $productsHtml -&gt;setTemplate('catalog/product/list.phtml')-&gt;setCollection($_productCollection); $pager = $magento_block-&gt;createBlock('page/html_pager', 'catalog/product_list')-&gt;setCollection($_productCollection); $productsHtml-&gt;setChild('pager', $pager); </code></pre> <p>Its taking all the product collection instead of just 20 items for creating toolbar. So i added a where condition in the productcollection itself as follows.</p> <pre><code>$_productCollection-&gt;getSelect()-&gt;where("order_items.qty_ordered &gt;= 50"); </code></pre> <p>This collection returns items which are sold more than 50 quantities. But what i want is exactly 20 items with correct pagination bar. </p> <p>How can i setLimit in pagination bar.</p> <p>The following also does not worked for me</p> <pre><code>$magento_block-&gt;createBlock('page/html_pager', 'catalog/product_list')-&gt;setCollection($_productCollection)-&gt;setLimit(20); </code></pre> <p><strong>Note:</strong> Am loading this product collection outside Magento Enterprise 1.9 version and not with in magento template. Can someone find whats the mistake am doing here?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload