2013-07-11 37 views
2

顯示特價商品在magento的銷售圖標。僅在主頁上顯示的不是所有頁面。顯示在特價商品magento上的銷售圖標。只在主頁上顯示不是所有頁面

代碼我在 應用已經編輯/設計/前端/默認/模板/目錄/從行號產品/ 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> 

此圖標在主頁只顯示不在所有頁面的產品列表中。我如何顯示所有頁面?

請幫我出這個

+0

小心比較日期像這個! 這個假設永遠不會發生: '$ today <= strtotime($ specialPriceToDate)' 因爲time()獲取完整的時間,getSpecialToDate()不會。 你只得到像這樣從時間日期: '$今天=日期(「Y-M-d」);' 並由此將其轉換爲unixtime –

回答

3

這是因爲你插入這樣的形象:

<img src="../images/sale-icon.png" width="101" height="58" class="onsaleicon" /> 

影像應放置在skin/frontend/{interface}/{theme}/images/,你應該引用它是這樣的:

<img src="<?php echo $this->getSkinUrl('images/sale-icon.png');?>" width="101" height="58" class="onsaleicon" /> 

[編輯]
有點題外話,但g要知道:不要使用Mage::getModel('catalog/product')->load($_product->getId())您需要的每種產品屬性。它比您想象的要慢得多。剛剛在後臺編輯您需要的屬性(特惠價,從特殊的價格和特殊價格)設置的現場Used in product listingYes,重新索引一切,你應該能夠直接使用:

$specialprice = $_product->getSpecialPrice(); 
$specialPriceFromDate = $_product->getSpecialFromDate(); 
$specialPriceToDate = $_product->getSpecialToDate(); 
+0

OK我已經把那如你所說。但只顯示在主頁產品中..不在類似頁面的內頁中。查看此URL http://reboot.co.in/shop – swamy

+0

首先確保您在主頁上使用相同的產品模板和類別中的那些。如果你這樣做,那麼很可能你的一個if語句返回false。 – Marius

+0

是的,我爲所有頁面使用相同的模板。 – swamy

相關問題