Order products in a category with "New" items listed first in Magento -


when displaying magento category possible have new products (products have "new from" , "new to" date) listed @ beginning of collection show on first page of category instead of default location based on current sort?

would necessary have 2 queries?

thanks!

code sort products news_from_date , news_to_date:-

$todaydate  = mage::app()->getlocale()->date()->tostring(varien_date::datetime_internal_format);  $productcollection->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'); 

you can view new products code @ class mage_catalog_block_product_new

(app/code/core/mage/catalog/block/product/new.php)

hope helps.


Comments