5

I try to limit the new products on the homepage with the following code:

        <block type="catalog/product_new" template="catalog/product/homepage-new-products.phtml">
            <action method="setProductsCount"><count>2</count></action>
        </block>

Unfortunately this does not work, the setProductsCount is ignored.

8 Answers 8

5

Take a look at Limit number of products shown on homepage, list.phtml

{{block type="catalog/product_list" limit="4" category_id="13" template="catalog/product/list.phtml"}}

To accomplish this using layout.xml then use setLimit

<action method="setLimit">4</action>

Eg

<block type="catalog/product_list" template="catalog/product/homepage-new-products.phtml">
    <action method="setLimit">4</action>
</block>
3

If you look at the _getProductCollection() method in the class Mage_Catalog_Block_Product_New you will see that the blocks collection has no way to limit the actual list of items.

It can set the page count, using setProductsCount Theoretically you can use this to limit the result, by not placing a pager as part of the block display, thus only the first page will be shown - the end effect is just a limit of the first page of products.

A while back, I did come up with a away to insert a limit (product_count) to catalog list filters. In my examples I use the CMS {{block}} tags, but it should also work from standard layout directives

You can read about this via my blog entry: http://www.proxiblue.com.au/blog/smarter-cms-category-product-limits/

This is also available as a module via github: https://github.com/ProxiBlue/CatalogListFilters

2
  • In 1.9.0.1 it actually reads ->setPageSize($this->getProductsCount())->setCurPage(1) so it looks like it returns one page, of size getProductsCount(), there is a setProductsCount function, that's why OP is trying to call it like that in his question
    – Richard
    Oct 30, 2014 at 8:21
  • good work .... it is help me a t today
    – Amit Bera
    Dec 4, 2015 at 21:28
0
<action method="setColumnCount"><columns>2</columns></action>
<action method="setProductsCount"><count>2</count></action>

Try it like this

1
  • Tried before, does not work either.
    – Michael
    Oct 29, 2014 at 13:07
0
{{block type="catalog/product_new" products_count="2" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/new.phtml"}}

Try this one :)

0

You can add "column_count" to use product limit

{{block type="catalog/product_new" column_count="5" template="catalog/product/new.phtml"}}

0

You can achieve the same using

$productCollection->setPageSize(2);

in your block class.

0

setProductsCount and setColumnCount did not do this

setProductsCount is define current perpage collection

and setColumnCount define no of column for collection

you need to limit on collection using action method

 <action method="setLimit"></action>
0

Try below code to display recent product:-

<?php
                            $allproduct = Mage::getModel('catalog/product')->getCollection()->setOrder('entity_id','desc')->setPageSize(5)->getData();
                            $_helper = $this->helper('catalog/output');
                            foreach($allproduct as $product){
                            echo '<div class="product_box">';
                            $obj = Mage::getModel('catalog/product');
                            $productid = $product['entity_id'];
                            $_product = $obj->load($productid); // Enter your Product Id in $product_id
                            $productName = $_product->getName();
                            $productDescription = $_product->getDescription();
                            $productImage = $_product->getImageUrl();
                            $productUrl = $_product->getProductUrl();
                            $productPrice = $_product->getPrice();
                            $addToCartUrl = Mage::helper('checkout/cart')->getAddUrl($_product);
                            echo '<a href="'.$productUrl.'"><img src="'.$productImage.'" alt="Shoes 1" /></a>';
                            echo '<p>"'.$productDescription.'"</p>';
                            echo '<p class="product_price">"'.$productPrice.'"</p>';
                            echo '<a href="'.$productUrl.'" class="detail"></a>';
                            echo "<div class='carousel-title'>";
                            echo $_product->getName();
                            echo "</div>";
                            echo '<a href="'.$addToCartUrl.'" class="addtocart"></a>';
                            echo '</div>';
                            }

                        ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.