Magento: Get new products programatically
To get new product collection in magento:-
$todayStartOfDayDate = Mage::app()->getLocale()->date() ->setTime('00:00:00') ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); $todayEndOfDayDate = Mage::app()->getLocale()->date() ->setTime('23:59:59') ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); /** @var $collection Mage_Catalog_Model_Resource_Product_Collection */ $collection = Mage::getResourceModel('catalog/product_collection') ->setVisibility(Mage::getSingleton('catalog/product_visibility') ->getVisibleInCatalogIds()); $collection = $collection->addMinimalPrice() ->addFinalPrice() ->addTaxPercents() ->addAttributeToSelect(Mage::getSingleton('catalog/config') ->getProductAttributes()) ->addUrlRewrite() ->addStoreFilter() ->addAttributeToFilter('news_from_date', array('or'=> array( 0 => array('date' => true, 'to' => $todayEndOfDayDate), 1 => array('is' => new Zend_Db_Expr('null'))) ), 'left') ->addAttributeToFilter('news_to_date', array('or'=> array( 0 => array('date' => true, 'from' => $todayStartOfDayDate), 1 => array('is' => new Zend_Db_Expr('null'))) ), 'left') ->addAttributeToFilter( array( array('attribute' => 'news_from_date', 'is'=>new Zend_Db_Expr('not null')), array('attribute' => 'news_to_date', 'is'=>new Zend_Db_Expr('not null')) ) ) ->addAttributeToSort('news_from_date', 'desc') ;
Thank you for the details, this is very helpful