Display new arrivals by category in Magento

Some times clients demand to show new arrivals product on home page or product listing page in magento store. Then its very easy to show that
For this load product collection and apply these filters


<?php 
/*Find the current date */ 
 $todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); 
/*Making collection of new arrivals*/
 $_productCollection = Mage::getModel('catalog/product')->getCollection()   
                ->addAttributeToSelect('*')
                ->setStoreId($storeId)
                ->addStoreFilter($storeId)
                ->addCategoryFilter($category)
                ->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', $this->getRequest()->getParam('dir'));
?>

Comments

Popular posts from this blog

Sort Products by popularity count in Magento

Safe name of a file by php