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

时间:2013-09-30 00:11:13

标签: php magento

我正在尝试在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>`

2 个答案:

答案 0 :(得分:2)

试试这个

这里

$ 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
            }

        }

        }
    }

答案 1 :(得分:0)

我是这样做的 在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;?>