Magento Add "new" or discount quantity label magento new label. discount label to the product

Source: Internet
Author: User

The bottom of the article is.

Add the "new" label to the new product. Shows the quantity of discounts for discount products.

You can add a piece of code to the catalog/product/list. phtml file in the template folder. The following code is used:

<? Php $ now_tm = Mage: getModel ('Core/date')-> timestamp (time ();?>


<! -- Add new -->
<? Php
$ New_str_tm = strtotime ($ _ product-> getNews_from_date ());
$ New_end_tm = strtotime ($ _ product-> getNews_to_date ());
?>
<Div style = "display: none">
<? Php echo "nows:". $ now_tm;?>
<? Php echo "start:". $ new_str_tm;?>
<? Php echo "end:". $ new_end_tm;?>
</Div>
<? Php if ($ new_str_tm> 0):?>
<? Php if ($ now_tm <$ new_end_tm) | ($ now_tm> $ new_str_tm )&&(! $ New_end_tm):?>
<Div class = "ico_new_bg"> NEW </div>
<? Php endif;?>
<? Php endif;?>
<! -- Special price -->
<? Php
$ Spe_end_tm = strtotime ($ _ product-> getSpecial_to_date ());
$ Spe_str_tm = strtotime ($ _ product-> getSpecial_from_date ());
$ Spe_pri =$ _ product-> getSpecial_price ();
?>
<? Php $ pri =$ _ product-> getResource ()-> getAttribute ('pric')-> getFrontend ()-> getValue ($ _ product)?>
<? Php if ($ now_tm <$ spe_end_tm) | ($ now_tm> $ spe_str_tm )&&(! $ Spe_end_tm):?>
<? Php if ($ spe_pri) & ($ spe_pri <$ pri):?>
<? Php $ percent = round (100-100 * $ spe_pri/$ pri, 2)?>
<Div class = "ico_percent_bg"> <? Php echo '-'. $ percent?> % </Div>
<? Php endif;?>
<? Php endif;?>
<! -- End -->


The above code is inserted to the corresponding position .. It is best to put it in <? Php // Grid Mode?> After this

After this is done. You also need to change the CSS. Display it in the corresponding position.

. Products-grid. ico_new_bg {height: 33px; font-size: 14px; line-height: 24px; color: # ffffff; background: url (".. /images/ico_bg.png "); position: absolute; margin:-10px-10px 0; padding: 0 10px 0; z-index: 10 ;}
. Products-grid. ico_percent_bg {height: 33px; font-size: 14px; line-height: 24px; color: # ffffff; background: url (".. /images/ico_bg.png "); position: absolute; margin:-10px-10px 0; padding: 0 10px 0; z-index: 10 ;}


The csscode is written under styles.css. Add to/* View Type: Grid .. Products-grid li. item: add the last two lines of code after this line.

Adjust the location of margin to suit your website.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.