Search code examples
phpmagentomagento-1.9.1

How to check if a product is new in Magento?


How to check if a product is new in Magento 1.9.0.1?

I tried:

    <?php if($_product->getNewProduct()) { ?>
          ...my HTML code...
    <?php } ?>

but it dosn't work. What's wrong with it?


Solution

  • I solved in this way:

        <?php
            $current_date = Mage::getModel('core/date')->date('Y-m-d');
            $from_date = substr($_product->getNewsFromDate(), 0, 10);
            $to_date = substr($_product->getNewsToDate(), 0, 10); 
    
            $new = ($current_date >= $from_date && $current_date <= $to_date) || ($from_date == '' && $current_date <= $to_date && $to_date != '') || ($from_date != '' && $current_date >= $from_date && $to_date == '') ;
        ?>
    
        <?php if($new == 1) { ?>
                 <img src="...
        <?php } ?>