Main aims:

To create New Arrivals page and Specials page that

+ work just like other category pages

+ can be filtered by normal Shopping Options including by Category

+ and have paging toolbar

Logic explanation:

Magento (current ver: 1.4.2) does not support New Arrivals page and Specials page even though it does have the options to setup a product as new/special product. In order to create these pages, I have searched and found some solutions that can display the new arrival products by simply creating a CMS page with a small block of code. However, it does not work as I expected that those pages did not have the filterable functionality as well as the paging toolbar. Therefore, I have come up with my own solution that uses the root category (in my sample is Our Collections category) as the base category for the New Arrivals page and the Special page. By adding “key=value” attribute into the URL, the New Arrivals page is differentiated with the Specials page by the different value entered.

For New Arrivals page, the attribute “type=new-arrivals” is added into the url as example below: …index.php/our-collections.html?type=new-arrivals.

For Specials page, the attribute “type=specials” is added into the url as example below: …index.php/our-collections.html?type=specials.

What we then have to do is updating a core function of Magento that loads product collection so that when the page above is clicked, it will load only new arrival / special products. The function updated is called _getProductCollection that can be found in the file app\code\core\Mage\Catalog\Block\Product\List.php. Please make sure that you have backed up this file before making any changes.

Apart from other small changes (eg. page title change, breadscrumb change), that are all important things that we have to do so that the page can work properly as a normal category page.

Steps to do:

Step 1: Updating the Magento core file: app\code\core\Mage\Catalog\Block\Product\List.php

Replacing thefunction _getProductCollection() with the following code:

protected function _getProductCollection()
{
$currentUrl = Mage::helper(‘core/url’)->getCurrentUrl();
$todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);

if (is_null($this->_productCollection)) {
$layer = $this->getLayer();
/* @var $layer Mage_Catalog_Model_Layer */
if ($this->getShowRootCategory()) {
$this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
}

// if this is a product view page
if (Mage::registry(‘product’)) {
// get collection of categories this product is associated with
$categories = Mage::registry(‘product’)->getCategoryCollection()
->setPage(1, 1)
->load();
// if the product is associated with any category
if ($categories->count()) {
// show products from this category
$this->setCategoryId(current($categories->getIterator()));
}
}

$origCategory = null;
if ($this->getCategoryId()) {
$category = Mage::getModel(‘catalog/category’)->load($this->getCategoryId());
if ($category->getId()) {
$origCategory = $layer->getCurrentCategory();
$layer->setCurrentCategory($category);
}
}
$this->_productCollection = $layer->getProductCollection();

$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());

if ($origCategory) {
$layer->setCurrentCategory($origCategory);
}
}

if (strpos($currentUrl, “type=new-arrivals”) !== false){    // if the string “type=new-arrivals” exists in the url then
$this->_productCollection = $this->_addProductAttributesAndPrices($this->_productCollection)
->addStoreFilter()
->addAttributeToFilter(‘news_from_date’, array(‘date’ => true, ‘to’ => $todayDate))
->addAttributeToFilter(‘news_to_date’, array(‘or’=> array(
0 => array(‘date’ => true, ‘from’ => $todayDate),
1 => array(‘is’ => new Zend_Db_Expr(‘null’)))
), ‘left’)
->addAttributeToSort(‘news_from_date’, ‘desc’);
}
elseif (strpos($currentUrl, “type=specials”) !== false) {    // if the string “type=specials” exists in the url then
$this->_productCollection = $this->_addProductAttributesAndPrices($this->_productCollection)
->addStoreFilter()
->addAttributeToFilter(‘special_from_date’, array(‘date’ => true, ‘to’ => $todayDate))
->addAttributeToFilter(‘special_to_date’, array(‘or’=> array(
0 => array(‘date’ => true, ‘from’ => $todayDate),
1 => array(‘is’ => new Zend_Db_Expr(‘null’)))
), ‘left’)
->addAttributeToSort(‘special_from_date’, ‘desc’);
}

return $this->_productCollection;
}

Step 2:

Changing the page title as it, by default, is “Our Collections“. Open the file app\design\frontend\default\[your theme]\template\catalog\category\view.phtml and find the line below

<h1><?php echo $_helper->categoryAttribute($_category, $_category->getName(), ‘name’) ?></h1>

and replace the whole line with the following code:

<?php
$currentUrl = Mage::helper(‘core/url’)->getCurrentUrl();
?>

<?php if (strpos($currentUrl, “type=new-arrivals”) !== false):?>
<h1><?php echo “New Arrivals” ?></h1>
<?php elseif (strpos($currentUrl, “type=specials”) !== false):?>
<h1><?php echo “Specials” ?></h1>
<?php else: ?>
<h1><?php echo $_helper->categoryAttribute($_category, $_category->getName(), ‘name’) ?></h1>
<?php endif; ?>

Step 3:

Create a New Arrivals link in your website (such as in homepage) that has the address below: [home url]/our-collections.html?type=new-arrivals.

Create a Specials link in your website (such as in homepage) that has the address below: [home url]/our-collections.html?type=specials.

Now you can click into the New Arrivals or Specials link to see the result. Make sure that you have created some products that are set as new products and special products so that the page won’t be empty.

Enjoy!