Magento Themes and Magento Extensions

How to Display New Products in Magento with Pagination?

Share

Displaying new products to a specific category in any Magento site , with pagination and a CMS page is really very complicated. The default functionality that Magento offers for latest products doesn’t just work. However, below is documented the method that will let you add new products to a Magento CMS page along with pulling up new products for any category you select, or for the entire site. Whether you are looking to include new products to your CMS page by category or for the whole site, it all depends upon you.

How to add new products with built-in Magento Tools?

Displaying or adding a list of new products in Magento through a default block is made possible without any coding issues or changes to Magento itself. This code allows you to roll out a roster of new products on the CMS page of your liking.

How to display new products in Magento with Pagination?

Following steps allow you to add new products to a Magento CMS page and show pagination for the products.

Below are given paths wherein you have to create the folders if they’ve not been created earlier.

app/code/local/Mage/Catalog/Block/Product

Below is the location where you have to create and place a new .php file:

app/code/local/Mage/Catalog/Block/Product/New.php

3. Below is the code that you have to add to your new.php file:

01 //Code

02 unsLimitPage();

10 return (isset($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : 12;

11 }// get_prod_count

12

13 function get_cur_page()

14 {

15 return (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 1;

16 }// get_cur_page

17

18 /**

19 * Retrieve loaded category collection

20 *

21 * @return Mage_Eav_Model_Entity_Collection_Abstract

22 **/

23 protected function _getProductCollection()

24 {

25 $todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);

26

27 $collection = Mage::getResourceModel(‘catalog/product_collection’);

28 $collection->setVisibility(Mage::getSingleton(‘catalog/product_visibility’)->getVisibleInCatalogIds());

29

30 $collection = $this->_addProductAttributesAndPrices($collection)

31 ->addStoreFilter()

32 ->addAttributeToFilter(‘news_from_date’, array(‘date’ => true, ‘to’ => $todayDate))

33 ->addAttributeToFilter(‘news_to_date’, array(‘or’=> array(

34 0 => array(‘date’ => true, ‘from’ => $todayDate),

35 1 => array(‘is’ => new Zend_Db_Expr(‘null’)))

36 ), ‘left’)

37 ->addAttributeToSort(‘news_from_date’, ‘desc’)

38 ->setPageSize($this->get_prod_count())

39 ->setCurPage($this->get_cur_page());

40

41 $this->setProductCollection($collection);

42

43 return $collection;

44 }// _getProductCollection

45 }// Mage_Catalog_Block_Product_New

46 ?>

4. Ok – now your New.php file, add your Magento CMS page and let it exude the new products.

How to add new products to a Magento Page alongside the Magento Block?

Do you remember those good old block code we got our products to display first? Well, that can be used again, but now it has to be modified to benefit from the list.phtml template file. Below is the block that you need to put in the Content area of your CMS page.

1 {{block type=”catalog/product_new” column_count=”6″ products_count=”0″ name=”home.catalog.product.new” alias=”product_homepage” template=”catalog/product/list.phtml”}}

Comments are closed.