zoukankan      html  css  js  c++  java
  • Magento给产品添加“new”或者折扣数量标签 magento new label. discount label

    文章最底部有效果图。

    给新产品添加“new”的标签。给折扣产品,显示出折扣的数量。

    这个可以自己写一段代码加在到模板文件夹下面的catalog/product/list.phtml中。 以下是代码

    <?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('price')->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 -->

    上面的这段代码插入到相应的位置。。最好是放在    <?php // Grid Mode ?> 这个后面

    这个弄好后。还要改CSS。让其显示在相应的位置。

    .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; }

    这段CSS代码添加到styles.css下面。添加到/* View Type: Grid */ 这个下面。.products-grid li.item,在这一行后面添加上两行代码。

    margin的位置自己调整适合自己网站的。

    下面这个是红色背景的图片。


    这里添加好以后。到你前台产品目录下面。就可以看到这个变化了!


  • 相关阅读:
    Pikachu漏洞平台---XSS(Cross-Site Scripting) 跨站脚本
    Pikachu漏洞练习平台(暴力破解模块)
    DVWA-- 不安全得验证码Insecure CAPTCHA
    DVWA-文件上传 File Upload
    DVWA之CSRF(跨站请求伪造)
    绑定方法与非绑定方法
    XML,面向对象基础
    configparser ,subprocess , xlrd ,xlwt 模块
    logging ,re 模块
    random,json,pickle,hashlib,shutil,hmac,shelve 模块
  • 原文地址:https://www.cnblogs.com/snake-hand/p/3149644.html
Copyright © 2011-2022 走看看