Get New Product In Magento

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

$collection = Mage::getModel(‘catalog/product’)
->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’)
->addAttributeToSort(‘created_at’, ‘desc’);
<?php $_productCollection = $collection; ?>
<?php if(count($_productCollection)<1): ?>
<?php echo $this->__(“There are no products matching the selection. Please provide a category ID.”) ?>
<?php else: ?>

<?php if ($now>=$newsFrom && $now<=$newsTo)?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php $_product = Mage::getModel(‘catalog/product’)->load($_product->getId()); ?>
<?php echo “<pre>”; print_r($_product->getName()); echo “</pre>”; ?>
<a href=”<?php echo $_product->getProductUrl() ?>”>
<img src=”<?php echo $this->helper(‘catalog/image’)->init($_product, ‘small_image’)->resize(213, 213); ?>” alt=”<?php echo $this->htmlEscape($_product->getName()) ?>” />
<?php endforeach ?>
<?php endif ;?>


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s