Get New Product In Magento

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

$collection = Mage::getModel(‘catalog/product’)
->getCollection()
->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): ?>
<div>
<?php echo $this->__(“There are no products matching the selection. Please provide a category ID.”) ?>
</div>
<?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()) ?>” />
</a>
<?php endforeach ?>
<?php endif ;?>

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s