【发布时间】:2016-08-08 19:43:09
【问题描述】:
在 magento 中的特价产品上显示促销图标。仅在主页上,并非在所有页面中都显示。
我编辑过的代码
app/design/frontend/default/template/catalog/product/list.html
从行号:95
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"` class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<?php
// Get the Special Price
$specialprice = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialPrice();
// Get the Special Price FROM date
$specialPriceFromDate = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialFromDate();
// Get the Special Price TO date
$specialPriceToDate = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialToDate();
// Get Current date
$today = time();
if ($specialprice):
if($today >= strtotime( $specialPriceFromDate) && $today <= strtotime($specialPriceToDate) || $today >= strtotime( $specialPriceFromDate) && is_null($specialPriceToDate)):
?>
<img src="../images/sale-icon.png" width="101" height="58" class="onsaleicon" />
<?php
endif;
endif;
?>
</a>
此图标仅显示在主页中,而不显示在页面的所有产品列表中。如何在所有页面中显示?
请帮我解决这个问题
【问题讨论】:
-
小心比较日期!这个假设永远不会发生:
$today <= strtotime($specialPriceToDate)因为 time() 获取完整时间而 getSpecialToDate() 没有。您只需要像这样获取时间的日期:$today = date('Y-m-d');并因此将其转换为 unixtime