0

I am struggling with a situation for last 2 days that i want to display the new products using pagination and all sorting and per page option enabled on the template i saw that there is no code for under core Block/New.php for such kind of functionality any one have solved this before please help to sort it out.

1 Answer 1

2

CMS Block

This is described in the magento wiki:

http://www.magentocommerce.com/wiki/groups/248/display_products_on_home_page

    {{block type="catalog/product_new" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/new.phtml"}}

I'm not sure, but I think you have to mark the products as new from ... until in the product's configuration.

Own block

The alternative is to implement a block like this:

<?php
class Namespace_ModuleName_Block_Newest extends Mage_Catalog_Block_Product_List
{

    /**
     * returns the product collection, ordered by created_at date
     *
     * @return Mage_Eav_Model_Entity_Collection_Abstract
     */
    protected function _getProductCollection()
    {
        if (!is_null($this->_productCollection)) {
            return $this->_productCollection;
        }
        $collection = parent::_getProductCollection();
        $collection->addOrder(
            'created_at',
            Mage_Catalog_Model_Resource_Product_Collection::SORT_ORDER_DESC
        );
        return $this->_productCollection;
    }
}
4
  • Thanks for reply but unfortunately this not what i was looking for i am setting the product as new using new from date and new to date attributes and this is what new.phtml phtml is built to display new products this is working but the pagination and other sorting options are not coming :-(
    – Ravi Soni
    Mar 15, 2013 at 7:40
  • just add the toolbar in your layout.xml. The block is extended from the product_list, so it should work with the toolbar out of the box Mar 15, 2013 at 9:07
  • Did my answer helped you? Did it solve your problem? Please mark it as solution. If not, what's the problem? Apr 7, 2013 at 1:23
  • Won't work as $collection would have only products of the specific category, not all new products that marked New from date
    – Sergei Guk
    Jul 5, 2013 at 18:10

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.