在Magento类别视图中显示折扣百分比



我一直在尝试显示类别清单中每个产品的折扣%而无需安装扩展名。

关于如何执行此操作的任何想法?

搜索了几个教程后,我找到了一种方法:

  1. 打开应用/设计/frontend/base/base/default/template/catalog/propert.phtml
  2. 找到"
  3. 在该行上方,添加:

    <?php if($_finalPrice < $_price): ?>
    <?php $_Percent = 100 - round(($_finalPrice / $_price)*100); ?>
        <p class="special-price">
            <span class="price" style="width: 50px; height; 50px; height: 50px;border-radius: 50%; background: red; color: white;position: relative;display: block;float: right;margin-top: -100px;text-align: center;/* padding: 5px; */line-height: 50px; font-weight: 800">ca
                <?php echo $_Percent; ?>%
            </span>
        </p>
    <?php endif; ?>
    

就是这样。但是一些建议:而不是修改基本/默认文件,而是在子主题中创建自己的版本。在样式表中使用适当的CSS而不是内联。

  • 开放:

app/design/frontend/base/base/default/template/catalog/propert/price.phtml

app/design/frontend/yourtheme/默认/template/catalog/propert/price.phtml

  • 找到:<?php endif; /* if ($_finalPrice == $_price): */ ?>

  • 该行上方添加: <?php // Display Discount percents start ?> <?php if($_finalPrice < $_price): ?> <?php $_savingPercent = 100 - round(($_finalPrice / $_price)*100); ?> <p class="special-price yoursaving"> <span class="label"><?php echo $this->__('Discount:') ?></span> <span class="price"> <?php echo $_savingPercent; ?>% </span> </p> <?php endif; ?> <?php // Display Discount percent end ?>

最新更新