0

I am not seeing the new label being applied on the catalog page. There are 2 labels that I have applied but only one is working.

Here is code; Sale Label

<?php if($this->helper('framework')->isSpecialProduct($_product)):?>
    <?php echo $this->__('sale_label') ?>
<?php endif;?>
New Label
<?php if($this->helper('framework')->isNewProduct($_product)):?>
    <?php echo $this->__('new_label') ?>
<?php endif; ?>

Sale label works no problem.. But I can't get the new label to apply. Even when I filter the new products on the page so it is only showing them (so I know I 100% have new items in catalog) it still will not show the label..

Any thoughts?

3
  • do you want to show it on product view page ? please share code for isNewProduct.
    – Pawan
    Feb 27, 2019 at 2:28
  • Which criteria do you use for the new products, i.e. the products added within a certain days range (week, month etc.) or by the fields Set Product as New from Date and Set Product as New to Date? Feb 27, 2019 at 5:12
  • @Pawan this code exists in the standard template for Magento on the template/catalog/list.phtml page and is as above(albiet modified echo text). As mentioned the isSpecialProduct works no worries. @MohitKumarArora I am using the Set Product as New from Date as the criteria for new on this instance. Do you think this differs to a new item just added? I have not tried a fresh stock add as all stock has been imported with no dates set for the items. Mar 1, 2019 at 1:09

1 Answer 1

0

I have achieved this with the following code

<?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) { ?> <span class="uk-label uk-label-success">New</span> <?php } ?>

Does what I want and works as intended from the dates in product info

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.