如何在洋红色的类别列表页面中显示销售图标


How to show sale icon in category list pages in magento

我正在尝试显示洋红色中保存金额百分比的销售图标,到目前为止,我成功地做到了这一点。但我面临的问题是销售图标显示在所有页面上,无论产品是否有特价。销售图标必须仅在有特价时显示。我在list.phtml中使用以下代码。我不是程序员。感谢您帮助更正这些代码,以便仅在有特价时才出现销售图标。提前致谢

<?php $specialprice = $_product->getSpecialPrice();
$regularprice = $_product->getPrice();
// Get the Special Price FROM date
$specialPriceFromDate = $_product->getSpecialFromDate();
// Get the Special Price TO date
$specialPriceToDate = $_product->getSpecialToDate();
// Get Current date
$today = time(); if ($specialprice)if($today >= strtotime( $specialPriceFromDate) && $today <= strtotime
($specialPriceToDate) || $today >= strtotime( $specialPriceFromDate) && is_null($specialPriceToDate))$discount = 100 
- round(($specialprice / $regularprice)*100); {?><span class="onsaleicon"><span class="onsaletext"> <?php echo 
$discount .'% OFF' ;?></span></span> <?php } ?></a>`

试试这个

这里

$stodate = 迄今为止的特价

$sfromdate = 从日期开始的特价

$date = date("Y-m-d H:i:s");
$special=$_product['special_price'];
$price=$_product['price'];
$stodate=$_product['special_to_date'];
$sfromdate=$_product['special_from_date'];
    if (!$special == null) {
        if (isset($sfromdate) and $date >= $sfromdate) {
        {
            if(isset ($stodate)){
                if($date <= $stodate ){
                     ?>
            <div class="onsaleicon">
                <span class="discounttext">
                    <?php
                    echo round(100 - ($special / $price) * 100) . "%";
                    ?>              
                </span>
            </div>              
            <?php
                }
            }else{
                 ?>
            <div class=""onsaleicon">
                <span class="discounttext">
                    <?php
                    echo round(100 - ($special / $price) * 100) . "%";
                    ?>              
                </span>
            </div>              
            <?php
            }
        }
        }
    }

这是我是如何做到的。
catalog/product/list.phtml顶部添加以下内容:

$_taxHelper  = $this->helper('tax');

并使用此代码来确定产品是否有特殊价格。如果特价是手动设置的,或者是由目录价格规则确定的,它将起作用。

<?php $_simplePricesTax = ($_taxHelper->displayPriceIncludingTax() || $_taxHelper->displayBothPrices());?>
<?php $_price = $_taxHelper->getPrice($_product, $_product->getPrice()) ?>
<?php $_regularPrice = $_taxHelper->getPrice($_product, $_product->getPrice(), $_simplePricesTax) ?>
<?php $_finalPrice = $_taxHelper->getPrice($_product, $_product->getFinalPrice()) ?>
<?php if ($_finalPrice < $_price): ?>
   YOUR SALE LABEL HERE
<?php endif;?>