1

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

2 回答 2

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
            }

        }

        }
    }
于 2013-09-30T12:44:00.647 回答
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;?>
于 2013-09-30T07:28:27.417 回答