Magento给产品添加“new”或者折扣数量标签 magento new label. discount label

来源:互联网 发布:分区删除数据恢复 编辑:程序博客网 时间:2024/04/24 08:18

文章最底部有效果图。

给新产品添加“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的位置自己调整适合自己网站的。

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


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


原创粉丝点击